Regular expression syntax examples: ^ [t] * $ ^ [t] * $ matches a blank line. D {2}-d {5} d {2}-d {5} verify that an ID number consists of a 2-character, a hyphen, and a 5-digit number. (. *). * 1 (. *). * 1 matches an HTML tag. The following table lists metacharacters and regular expressions.
Regular Expression Syntax example
Here are some examples of regular expressions that may be encountered:
/^ \ [\ T] * $/"^ \ [\ t] * $" matches a blank row.
/\ D {2}-\ d {5}/"\ d {2}-\ d {5}" verify whether an ID number consists of two characters, one
And a five-digit combination.
/<(. *)>. * <\/\ 1>/"<(. *)>. * <\/\ 1>" matches an HTML tag.
The following table shows a complete list of metacharacters and their behaviors in the context of a regular expression:
Character Description
\ Mark the next character as a special character, a literal character, or a suffix
A quote, or an octal escape character. For example, 'n' matches the character "n ". '\ N'
Match a linefeed. The sequence '\' Matches "\" and "\ (" matches "(".
^ Matches the start position of the input string. If the RegExp object's
The Multiline attribute. ^ also matches the position after '\ n' or' \ r.
$ Matches the end position of the input string. If the RegExp object's
The Multiline attribute. $ also matches the position before '\ n' or' \ r.
* 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" or "do" in "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 ,}'
It is equivalent to 'O + '. 'O {0,} 'is equivalent to 'O *'.
Both {n, m} m and n are non-negative integers, where n <= m. Match at least n times and match at most
Configuration m times. Liu, "o {1, 3}" will match 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.
? When this character is followed by any other delimiter (*, + ,?, {N}, {n ,},
{N, m}), the matching mode is not greedy. As few non-greedy models as possible
Matches the searched string, while the default greedy mode matches as many searched strings as possible.
String. For example, for strings "oooo", 'O ++? 'Will match a single
"O", and 'O + 'will match all 'o '.
. Match any single character except "\ n. To match any name including '\ n'
For the characters, use the mode like '[. \ n.
(Pattern) matches pattern and obtains this match. The obtained matching can be obtained from
Obtain the Matches set and use the SubMatches set in VBScript.
$0… is used in Visual Basic Scripting Edition... $9 attribute. Yes
Use '\ (' or '\)' to match the parentheses '\)'.
(? : Pattern) matches pattern but does not get the matching result, that is, this is a non-Retrieved
Configuration, not stored for future use. This is a combination of "or" characters (| ).
Each part of a mode is very useful. For example, 'industr (? : Y | ies ).
Is a simpler expression than 'industry | industries.
(? = Pattern) forward pre-query, matching the search character at the beginning of any string that matches pattern
String. This is a non-get match, that is, the match does not need to be obtained for later
. For example, 'windows (? = 95 | 98 | NT | 2000) 'can match "Windows
"Windows" in 2000 ", but cannot match" Windows "in" Windows3. 1 ".
Pre-query does not consume characters, that is, after a match occurs
Start the next matching search immediately after configuration, instead of starting from the character that contains the pre-query
.
(?! Pattern) Negative pre-query, in any does not match Negative lookahead matches
Search string at any point where a string not matching
Match the string at the beginning of the pattern. This is a non-Retrieved horse
Configuration, that is, the matching does not need to be obtained for future use. For example, 'windows
(?! 95 | 98 | NT | 2000) 'can match "Windows" in "Windows 3.1 ",
But cannot match "Windows" in "Windows 2000 ". Pre-query does not consume words
In other words, after a match occurs, it is enabled immediately after the last match.
Starts the next matched search, instead of starting after the pre-query characters.
X | y matches x or y. For example, 'Z | food' can match "z" or "food ". '(Z | f)
'Ood 'Matches "zood" or "food ".
[Xyz] character set combination. Match any character in it. For example, '[ abc] 'can
Match 'A' in "plain '.
[^ Xyz] combination of negative character sets. Match any character not included. For example, '[^ abc]' can
Match 'P' in "plain '.
[A-z] character range. Matches any character in the specified range. For example, '[a-z]' can match
Any lowercase letter in the range of 'A' to 'Z.
[^ A-z] negative character range. Matches any character that is not within the specified range. For example,
'[^ A-z]' can match any character that is not in the range of 'A' to 'Z.
\ B matches a word boundary, that is, the position between a word and a space. For example,
'Er \ B 'can match 'ER' in "never", but cannot match in "verb"
'.
\ B matches non-word boundaries. 'Er \ B 'can match 'ER' in "verb", but cannot match
With the 'ER' in "never '.
\ Cx matches the control characters specified by x. For example, \ cM matches a Control-M or
Carriage return. The value of x must be either a A-Z or a-z. Otherwise, consider c as
The original 'C' characters.
\ D matches a numeric character. It is equivalent to [0-9].
\ D matches a non-numeric character. It is equivalent to [^ 0-9].
\ F matches a break. It is equivalent to \ x0c and \ cL.
\ N matches a linefeed. It is equivalent to \ x0a and \ cJ.
\ R matches a carriage return. It is equivalent to \ x0d and \ cM.
\ S matches any blank characters, including spaces, tabs, and page breaks. Equivalent
[\ F \ n \ r \ t \ v].
\ S matches any non-blank characters. It is equivalent to [^ \ f \ n \ r \ t \ v].
\ T matches a tab. It is equivalent to \ x09 and \ cI.
\ V matches a vertical tab. It is equivalent to \ x0b and \ cK.
\ W matches any word characters that contain underscores. It is equivalent to '[A-Za-z0-9 _]'.
\ W matches any non-word characters. It is equivalent to '[^ A-Za-z0-9 _]'.
\ Xn matches n, where n is the hexadecimal escape value. The hexadecimal escape value must be true.
The length of two numbers. For example, '\ x41' matches "". '\ X041' is equivalent
In '\ x04' & "1 ". The regular expression can use ASCII encoding ..
\ Num matches num, where num is a positive integer. References to the obtained matching.
For example, '(.) \ 1' matches two consecutive identical characters.
\ N identifies an octal escape value or a backward reference. If at least n before \ n
And n is the backward reference. Otherwise, if n is Octal
Number (0-7), then n is an octal escape value.
\ Nm identifies an octal escape value or a backward reference. If at least
Is preceded by at least nm get subexpression, then the nm is after
Reference. If at least n records are obtained before \ nm, n is a subject
Backward reference of the word m. If none of the preceding conditions are met, if both n and m are
If the octal value is 0-7, \ nm matches the octal escape value nm.
\ Nml if n is an octal digit (0-3) and m and l are octal digits (0-3-
7), match the octal escape value nml.
\ Un matches n, where n is a Unicode word represented by four hexadecimal numbers
. For example, \ u00A9 matches the copyright symbol (?).