官术网_书友最值得收藏!

Escaping special regex metacharacters and escaping rules inside the character classes

We know that . matches any character, [ and ] are used for character classes, { and } are used for limiting quantifiers, and ? , *, and + are used for various quantifiers. To match any of the metacharacters literally, one needs to escape these characters using a backslash (\ ) to suppress their special meaning. Similarly, ^ and $ are anchors that are also considered regex metacharacters.

Let's see some examples of escaping metacharacters in regular expressions.

The following regex matches the string, a.b?:

     a\.b\? 

The following regex matches the string, {food}:

    \{food\} 

The following regex matches the string, abc:][}{:

    abc:\]\[\}\{ 

The following regex matches the string, $25.50:

    \$\d+\.\d+

The following regex matches the string, ^*+.:

    \^\*\+\. 
主站蜘蛛池模板: 恩施市| 濮阳市| 比如县| 宁城县| 扬中市| 泸水县| 靖安县| 关岭| 平邑县| 宁强县| 汤阴县| 阿瓦提县| 兴国县| 云龙县| 阿尔山市| 阿拉善盟| 夏津县| 略阳县| 贵州省| 静乐县| 肥东县| 临清市| 寿宁县| 贵港市| 天柱县| 神池县| 加查县| 张掖市| 萨迦县| 炎陵县| 隆德县| 习水县| 湖口县| 治县。| 团风县| 沁水县| 鹤庆县| 阜康市| 榕江县| 泰安市| 威信县|