Regular expression syntax

Source: Internet
Author: User

Address: http://www.yesky.com/imagesnew/software/vbscript/html/jsgrpRegExpSyntax.htm

 

 

A regular expression is composed of common characters (such as characters a
Z) and special characters (calledMetacharacters. This mode describes one or more strings to be matched when searching the text subject. A regular expression is used as a template to match a character pattern with the searched string.

Here are some examples of regular expressions that may be encountered:

Visual Basic Scripting Edition VBScript Match
/^ \ [\ T] * $/ "^ \ [\ T] * $" Matches a blank row.
/\ D {2}-\ d {5 }/ "\ D {2}-\ d {5 }" Verify that an ID number consists of a 2-digit, a hyphen, and a 5-digit number.
/<(. *)>. * <\/\ 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, a back reference, 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. IfRegExpObjectMultilineProperty, ^ matches
Location after '\ n' or' \ R.
$ Matches the end position of the input string. IfRegExpObjectMultilineAttribute, $ also matches
'\ 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 ". + Equivalent
{1 ,}.
? Match the previous subexpression zero or once. For example, "do (es )? "Can match" do "in" do "or" does ".? Equivalent
{0, 1 }.
{N} NIs a non-negative integer. MatchedNTimes. For example, 'O {2} 'cannot match
'O', but can match the two o in "food.
{N,} NIs a non-negative integer. At least matchNTimes. For example, 'O {2,} 'cannot match
'O', but can match all o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O {0,} 'is equivalent to 'o *'.
{N,M} MAndNAll are non-negative integers, whereN<=M. Least match
NTimes and most matchingMTimes. Liu, "o {1, 3}" will match the first three o in "fooooood. 'O {0, 1} 'is equivalent
'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})
Later, the matching mode is non-greedy. The non-Greedy mode matches as few searched strings as possible, while the default greedy mode matches as many searched strings as possible. For example, for strings "oooo", 'O ++? '
A single "o" will be matched, while 'o + 'will match all 'O '.
. Matches any single character except "\ n. To match any character including '\ n', use' [. \ n]'
.
(Pattern) MatchPatternAnd obtain the matching. The obtained match can be obtained from the generated Matches set. It is used in VBScript.
SubMatchesSet, which is used in Visual Basic Scripting Edition$0...$9
Attribute. To match the parentheses, use '\ (' or '\)'.
(? :Pattern) MatchPatternBut does not get the matching result, that is, this is a non-get match and is not stored for future use. This is using the "or" Character
(|) It is very useful to combine all parts of a mode. For example, 'industr (? : Y | ies'
A simpler expression.
(? =Pattern) Forward pre-query, in any matchPattern
To start from the string. This is a non-get match, that is, the match does not need to be obtained for future use. For example, 'windows (? = 95 | 98 | NT | 2000) 'can match
"Windows" in "Windows 2000", but cannot match "Windows 3.1"
"Windows ". Pre-query does not consume characters, that is, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters.
(?!Pattern) Negative pre-query, in any does not match Negative lookahead matches the search string at any
Point where a string not matchingPattern
To start from the string. This is a non-get match, that is, the match 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 2000"
"Windows ". Pre-query does not consume characters. That is to say, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters.
X|Y MatchXOrY. For example, 'z | food' can match "z" or "food ". '(Z | f) ood'
Match "zood" or "food ".
[Xyz] Character Set combination. Match any character in it. For example, '[abc]' can match 'A' in "plain '.
[^Xyz] Negative value character set combination. 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 Match A Word boundary, that is, the position between a word and a space. For example, 'er \ B 'can match 'er' in "never", but it cannot match
'Er' in "verb '.
\ B Match non-word boundary. 'Er \ B 'can match 'er' in "verb", but cannot match
'Er '.
\ CX MatchingXThe specified control character. For example, \ cM matches a Control-M or carriage return character.XMust be
A-Z or one of a-z. Otherwise, c is treated as an original 'C' character.
\ D Match a numeric character. It is equivalent to [0-9].
\ D Match a non-numeric character. It is equivalent to [^ 0-9].
\ 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.
\ S Matches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [\ f \ n \ r \ t \ v].
\ S Match any non-blank characters. It is equivalent to [^ \ f \ n \ r \ t \ v].
\ T Match a tab. It is equivalent to \ x09 and \ cI.
\ V Match a vertical tab. It is equivalent to \ x0b and \ cK.
\ W Match any word characters that contain underscores. It is equivalent to '[A-Za-z0-9 _]'.
\ W Match any non-word characters. It is equivalent to '[^ A-Za-z0-9 _]'.
\ XN MatchN, WhereNIt is a hexadecimal escape value. The hexadecimal escape value must be determined by the length of two numbers. For example, '\ x41'
Match "". '\ X041' is equivalent to '\ x04' & "1 ". The regular expression can use ASCII encoding ..
\Num MatchNum, WhereNumIs a positive integer. References to the obtained matching. For example, '(.) \ 1'
Match two consecutive identical characters.
\N Identifies an octal escape value or a backward reference. If \NAt leastNObtained subexpressionsN
Is backward reference. Otherwise, ifNIs an octal digit (0-7 ),NIt is an octal escape value.
\Nm Identifies an octal escape value or a backward reference. If \NmAt least is preceded by at least
NmObtain the child expression, thenNmIs backward reference. If \NmAt leastNN
Is followed by textM. If none of the preceding conditions are metNAndMAll are Octal numbers (0-7), then
\NmMatch the octal escape ValueNm.
\Nml IfNIt is an octal digit (0-3) andMAndLAll are Octal numbers
(0-7), matching the octal escape ValueNml.
\ UN MatchN, WhereNIt is a Unicode character represented by four hexadecimal numbers. For example, \ u00A9
Match the copyright symbol (?).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.