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

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, ^*+.:

    \^\*\+\. 
主站蜘蛛池模板: 陈巴尔虎旗| 双桥区| 亚东县| 钟山县| 泰顺县| 福贡县| 宝兴县| 茶陵县| 津市市| 平邑县| 东平县| 吉安县| 昌邑市| 天峨县| 凤山县| 南召县| 延安市| 林西县| 资溪县| 崇仁县| 大田县| 筠连县| 长兴县| 宜昌市| 保靖县| 邛崃市| 青川县| 塘沽区| 瑞安市| 茶陵县| 临泽县| 余干县| 长沙县| 汉中市| 尼勒克县| 荆门市| 连山| 六安市| 休宁县| 关岭| 万宁市|