Character interpretation of regular expressions

\ : Escapes. For example, 'n' matches the character "n", while '\n' matches a newline. '\\'match"\".

^ : matches the starting position of the input string.

$ : Matches the end of the input string.

+ : means that the preceding character can appear one or more times. For example, runoo+b , can match runoob , runooob , runoooooob , etc.

* : means that the preceding character can appear zero or more times. runoo+b , can match runoob , runooob , runoooooob , etc.

? : Represents that the preceding character can appear at most once ( 0 or 1 ). colou?r can match color or colour . 

{n} : Match a certain number of n times. For example, ' 0{2} ' would not match the ' o ' in " Bob " , but would match the ' oo ' in " food " .

{n,} : Match at least n times.

{n, m} : n <= m , at least n times and at most m times.

? : When the character immediately follows any one of the other qualifiers ( * , + , ?, {n} , {n, m} ), the matching pattern is non-greedy. Match as little as possible to the searched string, for example, for the string " oooo ", ' o+? ' will match a single ' o ', and ' o+ ' will match all ' o 's.

. : matches any single character except newlines (\n, \r). To match any character including '\n', use a pattern like " (.|\n) ".

x | y : matches x or y .

[xyz]: Character set. Matches any one of the included characters. For example, '[abc]' can match 'a' in "plain".

[^xyz]: Set of negative characters. Matches any character not included. For example, '[^abc]' can match 'p', 'l', 'i', 'n' in "plain".

[az]: Match any character within the specified range.

[^az]: Match any character not in the specified range.

\b: Match a word boundary, i.e. the position between a word and a space. For example, 'er\b' can match the 'er' in "never", but not the 'er' in "verb".

\B: Match a non-word boundary. For example, 'er\b' cannot match 'er' in "never", but can match 'er' in "verb".

\d: Match a digit character. Equivalent to [0-9].

\D: Match a non-digit character. Equivalent to [^0-9].

\f: Match a form feed.

\n: Match a newline.

\r: Matches a carriage return.

\s: matches any whitespace character.

\S: matches any non-whitespace character.

\t: Match a tab character.

\v: Matches a vertical tab.

\w: matches letters, numbers, underscores. Equivalent to [A-Za-z0-9_].

\W: Matches non-letters, numbers, underscores. Equivalent to [^A-Za-z0-9_].

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324815693&siteId=291194637