- Java 9 Regular Expressions
- Anubhava Srivastava
- 130字
- 2021-07-02 18:58:37
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, ^*+.:
\^\*\+\.
推薦閱讀
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- ASP.NET Core 5.0開發入門與實戰
- Visual FoxPro 程序設計
- INSTANT CakePHP Starter
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Cassandra Data Modeling and Analysis
- JavaScript動態網頁開發詳解
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- QGIS By Example
- MATLAB 2020從入門到精通
- Building Machine Learning Systems with Python(Second Edition)
- Swift語言實戰晉級
- OpenCV 3 Blueprints
- JSP程序設計與案例實戰(慕課版)
- Spark技術內幕:深入解析Spark內核架構設計與實現原理