This article abstracts the content of several articles, briefly introduces ATL Catlregexp,greta, Boost::regex, and other regular expression libraries, which enable us to easily take advantage of the great power of the regular library, to facilitate our work.
Regular expression syntax
| Word metacharacters |
Significance |
| . |
Match a single character |
| [ ] |
Specifies a character class that matches any character within the square brackets. Example: [ABC] matches "a", "B" or "C". |
| ^ |
If ^ appears at the beginning of the character class, it negates the character class, and this negative character class matches the character within the square brackets. For example: [^ABC] matches characters except "A", "B" and "C". If ^ precedes the regular expression, it matches the beginning of the input, example: ^[ABC] matches the input beginning with "A", "B", or "C". |
| - |
In the character class, specify the range of a character. For example: [0-9] matches the number of "0" to "9". |
| ? |
Indicates that the previous expression is optional and can match once or no match. For example: [0-9][0-9]? Match "2" or "12". |
| + |
Indicates that the previous expression matches one or more times. For example: [0-9]+ Match "1", "13", "666", etc.). |
| * |
Indicates that an expression before * matches 0 or more times. |
| ??, +?, *? |
?, + and * are not greedy match versions, they match as few characters as possible, while?, + and * are greedy versions, matching as many characters as possible. For example: Enter "<abc><def>", then <.*?> match "<abc>", and <.*> matches "<abc><def>". |
| ( ) |
Grouping operators. For example: (\d+,) *\d+ matches a string of digits separated by commas, such as "1" or "1,23,456". |
| \ |
Escape character, escaping the character that follows. For example, [0-9]+ matches one or more numbers, and [0-9]\+ matches a number followed by a plus sign. The backslash \ is also used to represent abbreviations, and \a represents any number or letter. If \ is immediately followed by a number n, it matches the nth matching group (starting from 0), for example, <{.*?} >.*?</\0> match " |
| $ |
At the end of the regular expression, it matches the end of the input. For example: [0-9]$ matches the last number entered. |
| | |
Spacer, separating two expressions to correctly match one of them, for example: T|the matches "the" or "the". |
Abbreviation match
| Abbreviation |
The |
| \a |
Letters, numbers ([a-za-z0-9]) |
| \b |
Space (blank): ([\\t]) |
| \c |
Letter ([a-za-z]) |
| \d |
Decimal number ([0-9]) |
| \h |
hexadecimal number ([0-9a-fa-f]) |
| \ n |
Line Wrap: (\r| ( \r?\n)) |
| \q |
Reference string (\ "[^\"]*\ ") | (\''''[^\'''']*\'''') |
| \w |
A paragraph of text ([a-za-z]+) |
| \z |
An integer ([0-9]+) |