Special characters in Regular Expressions:
Character
Meaning: For characters, it usually indicates the literal meaning, indicating that the subsequent characters are special characters, not explained.
For example, if/B/matches character B by adding a backslash (/B/) before character B, the character becomes a special character, indicating
Match the dividing line of a word.
Or:
For a few characters, it is generally described as special. It is pointed out that the subsequent characters are not special, but should be interpreted literally.
For example, * is a special character that matches any character (including 0 characters). For example,/a */indicates that it matches 0 or multiple a characters.
To match the literal *, add a backslash before a. For example,/a */matches *.
Character ^
Meaning: The matched characters must be at the frontend.
For example,/^ A/does not match A in "an A,", but matches A in the top of "An.
Character $
Meaning: similar to ^, it matches the last character.
For example,/t $/does not match t in "eater", but matches t in "eat.
Character *
Meaning: match the first character of * 0 or n times.
For example,/bo */matches boooo in "A ghost booooed" or B in "A bird warbled", but does not match "A goat g
Any character in runted.
Character +
Meaning: match the character before the plus sign once or n times. It is equivalent to {1 ,}.
For example,/a +/matches all a in a and caaaaaaandy. In "candy.
Character?
Meaning: match? The first character is 0 or 1 time.
Example:/e? Le? /Match the le in el in "angel" and "angle.
Character.
Meaning: (decimal point) match all single characters except line breaks.
For example,/. n/matches an and on in "nay, an apple is on the tree", but does not match nay.
Character (x)
Meaning: Match x and record the matched value.
For example,/(foo)/matches and records foo in "foo bar. Matching substrings can be returned by the element [1],..., [n] In the result array.
Returned by RegExp object attributes $1,..., $9.
Character x | y
Meaning: Match x or y.
For example,/green | red/matches green in "green apple" and red in "red apple.
Character {n}
Meaning: Here n is a positive integer. Match the previous n characters.
For example:/a {2}/does not match a in "candy,", but matches the first two in "caandy," All a and "caaandy ."
A.
Character {n ,}
Meaning: Here n is a positive integer. Match at least n FIRST characters.
For example,/a {2,} does not match a in "candy", but matches all a in "caandy" and "caaaaaaandy ."
Character {n, m}
Meaning: both n and m are positive integers. Match at least n characters at most before m.
For example,/a {}/does not match any character in "cndy", but matches the first two characters in "candy," a, "caandy ,"
A and "caaaaaaandy" in the first three a, note: Even if "caaaaaaandy" has many a, but only matches the first three
A is "aaa ".
Character [xyz]
Meaning: A one-character list that matches any character in the list. You can use a hyphen to indicate a character range.
For example, [abcd] is the same as [a-c. They match B in "brisket" and c in "ache.
Character [^ xyz]
Meaning: A character complement, that is, it matches everything except the listed characters. You can use a hyphen to indicate
Character range.
For example, [^ abc] is equivalent to [^ a-c]. They first match h in r and "chop." in "brisket.
Character [B]
Meaning: match a space (do not confuse with B)
Character B
Meaning: match the boundary of a word, such as a space (do not confuse it with [B)
For example,/bnw/matches no in "noonday",/wyb/matches ly in "possibly yesterday.
Character B
Meaning: match the non-dividing line of a word
For example,/wBn/matches on in "noonday",/yBw/matches ye in "possibly yesterday.
Character cX
Meaning: X is a control character. Matches the control character of a string.
For example,/cM/matches control-M in a string.
Character d
Meaning: matching a number is equivalent to [0-9].
For example,/d/or/[0-9]/matches 2 in "B2 is the suite number.
Character D
Meaning: match any non-number, which is equivalent to [^ 0-9].
For example,/D/or/[^ 0-9]/matches B in "B2 is the suite number.
Character f
Meaning: match a form character
CHARACTER n
Meaning: match a linefeed.
Character r
Meaning: match a carriage return.
Character s
Meaning: match a single white space character, including space, tab, form feed, line feed, equivalent to [fnrtv].
For example,/sw */matches bar in "foo bar.
Character S
Meaning: match a single character except the white space character, which is equivalent to [^ fnrtv].
For example,/S/w * matches foo in "foo bar.
Character t
Meaning: match a tab
Character v
Meaning: match a top Tab
Character w
Meaning: match all numbers, letters, and underscores, equivalent to [A-Za-z0-9 _].
For example,/w/matches 3 in "apple," a, "$5.28," 5, and "3D.
Character W
Meaning: match other characters except numbers, letters, and underscores, equivalent to [^ A-Za-z0-9 _].
For example:/W/or/[^ $ A-Za-z0-9 _]/matches % in "50%.
CHARACTER n
Meaning: Here n is a positive integer. Match the n value of the last substring of a regular expression (left parentheses ).
For example:/apple (,) sorange1/matches apple, orange, cherry, peach ."
There is a more complete example.
Note: If the number in the left parentheses is smaller than the number specified by n, n removes the octal escape of a row as the description.
Ooctal and xhex
Meaning: ooctal here is an escape value of octal, and xhex is a hexadecimal escape value, allowing ASCII code to be embedded in a regular expression.