Detailed explanation of operators and instructions in the regular expression tutorial, regular expression Operators
This article describes the operators and descriptions in regular expressions. We will share this with you for your reference. The details are as follows:
1. common characters
Including all printed and non-printed characters that are not explicitly specified as metacharacters, such as uppercase and lowercase letters, numbers, and punctuation marks.
Ii. metacharacters
Metacharacters are characters with special meanings in regular expressions. Because metacharacters have special meanings in regular expressions, they cannot represent themselves. They must be escaped by adding a backslash prefix to them, the escape sequence will match the character itself rather than its special metacharacters. For example, [indicates the start of a character set combination. If you want to match [in a regular expression, you need to reference \ [in this way to represent [itself.
^ |
Matches the start position of the input string. Unless used in the square brackets expression, this character set is not accepted. To match the ^ character itself, use \ ^. |
$ |
Matches the end position of the input string. If multi-row match is set, $ also matches '\ n' or' \ R '. To match the $ character, use \ $. |
() |
Mark the start and end positions of a subexpression. Subexpressions can be obtained for future use. To match these characters, use [Math Processing Error]. |
? |
Match the previous subexpression zero or once, or specify a non-Greedy qualifier. To match? Character, use \?. |
* |
Matches the previous subexpression zero or multiple times. To match * characters, use \*. |
+ |
Match the previous subexpression once or multiple times. To match + characters, use \ +. |
. |
Match any single character except linefeed \ n. To match., use \. |
[] |
Mark the start and end of a character set. To match [or], use [Math Processing Error]. |
\ |
Mark the next character as a special character, a literal character, or backward reference, or an octal escape character. For example, 'n' matches the character 'n '. '\ N' matches the line break. The sequence '\' matches "\", while '\ (' matches "(". |
| |
Specifies a choice between two items. To match |, use \ |. |
{} |
Mark the start and end of the qualifier expression. To match {or}, use \ {or \}. |
3. Non-printable characters
\ Cx |
Match the control characters specified by x. For example, \ cM matches a Control-M or carriage return character. The value of x must be either a A-Z or a-z. Otherwise, c is treated as an original 'C' character. |
\ F |
Match a form feed. It is equivalent to \ x0c and \ cL. |
\ N |
Match A linefeed. It is equivalent to \ x0a and \ cJ. |
\ R |
Match a carriage return. It is equivalent to \ x0d and \ cM. |
\ T |
Match a tab. It is equivalent to \ x09 and \ cI. |
\ V |
Match a vertical tab. It is equivalent to \ x0b and \ cK. |
4. Pre-Defined Characters
. |
Any character (it may or may not match the terminator \ r \ n) |
\ D |
Number, equivalent to [0-9] |
\ D |
Non-number, equivalent to [^ 0-9] |
\ S |
Blank characters, equivalent to [\ t \ n \ x0B \ f \ r] |
\ S |
Non-blank characters, equivalent to [^ \ s] |
\ W |
Word character, equivalent to [a-zA-Z_0-9] |
\ W |
Non-word characters, equivalent to [^ \ w] |
\ B |
Boundary before or after a word |
\ B |
Non-word boundary |
5. POSIX characters
[: Alnum:] |
Any letter or number, equivalent to a [a-zA-Z0-9] |
[: Alpha:] |
Any letter is equivalent to [a-zA-Z] |
[: Blank:] |
Space or tab, equivalent to [\ t] |
[: Cntrl:] |
ASCII control characters (ASCII 0 to 31, plus ASCII127) |
[: Digit:] |
Any number is equivalent to [0-9]. |
[: Graph:] |
Any printable character, excluding spaces |
[: Lower:] |
Any lowercase letter, equivalent to [a-z] |
[: Print:] |
Any printable character |
[: Punct:] |
It does not belong to any character of [: alnum:] or [: cntrl :] |
[: Space:] |
Any blank character, including space, is equivalent to [^ \ f \ n \ r \ t \ v] |
[: Upper:] |
Any capital letter, equivalent to a [A-Z] |
[: Xdigit:] |
Any hexadecimal number is equivalent to a [a-fA-F0-9] |
6. Qualifier
* |
Matches the previous subexpression zero or multiple times. For example, zo * can match "z" and "zoo ". * Is equivalent to {0 ,}. |
+ |
Match the previous subexpression once or multiple times. For example, 'Zo + 'can match "zo" and "zoo", but cannot match "z ". + Is equivalent to {1 ,}. |
? |
Match the previous subexpression zero or once. For example, "do (es )? "Can match" do "in" do "or" does ".? It is equivalent to {0, 1 }. |
{N} |
N is a non-negative integer. Match n times. For example, 'O {2} 'cannot match 'O' in "Bob", but can match two o in "food. |
{N ,} |
N is a non-negative integer. Match at least n times. For example, 'O {2,} 'cannot match 'O' in "Bob", but can match all o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O {0,} 'is equivalent to 'o *'. |
{N, m} |
Both m and n are non-negative integers, where n <= m. Match at least n times and at most m times. For example, "o {1, 3}" matches the first three o in "fooooood. 'O {0, 1} 'is equivalent to 'o? '. Note that there must be no space between a comma and two numbers. |
Here we only classify some operators used in regular expressions according to different functions, which is not necessarily accurate, just to illustrate the operators in regular expressions.
PS: here we will provide two very convenient Regular Expression tools for your reference:
JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript
Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg
I hope this article will help you learn regular expressions.