Introduction to C Regular Expression Escape Characters

  • 2021-10-27 08:37:27
  • OfStack

Regular expression (regular expression) describes a string matching pattern, which can be used to check whether a string contains a certain substring, replace the matching substring, or take out a substring that meets a certain condition from a string.

Escape matching syntax:

"\" + Actual Character\. * +? () {} ^ $[] For example:\\ Matches the character "\"

\ n Matching Line Breaks

\ r Match Enter

\ t Match Horizontal Tabs

\ v Match Vertical Tab Characters

\ f Match Page Change

\ nnn matches 1 octal ASCII

\ xnn matches 1 hexadecimal ASCII

\ unnnn matches 4 hexadecimal Uniode

\ c + Caps Match Ctrl-Caps for example:\ cS-Match Ctrl+S

Note:

Enter double quotation marks in a string of type @ "" to write two double quotation marks side by side, such as:

If you want to express: James "Wu"

To write: @ "James" "Wu" ""

PS: The backslash (\) in a regular expression indicates one of the following values:

The following characters are special characters, as shown in the table in the following section. For example,\ b is the anchor point indicating that a regular expression match should start at the word boundary,\ t represents a tab, and\ x020 represents a space.

Characters that should be interpreted as unescaped language constructs should be interpreted literally. For example, a curly brace ({) begins to define a qualifier, and a backslash followed by a curly brace (\ {) indicates that the regular expression engine should match the curly brace. Similarly, a single backslash marks the beginning of an escaped language construct, and two backslashes (\\) indicate that the regular expression engine should match the backslash.


Related articles: