Regular expression syntax

xiaoxiao2021-03-06  24

A regular expression is a text mode composed of normal characters (such as characters a to z) and special characters (called metammatics). This mode describes one or more strings to be matched when the text body is looking for. Regular expression As a template, a character mode matches the search string.

Here are some regular expressions that may encounter:

Visual Basic Scripting Edition

VBScript

match

/ ^ / [/ t] * $ /

"^ / [/ t] * $"

Match a blank line.

// d {2} - / d {5} /

"/ d {2} - / d {5}"

Verify that an ID number is composed of a 2-digit, a hyphen, and a 5-digit.

/< (.*)>.*< / / / 10//

"<(. *)>. * "

Match an HTML tag.

The table below is a complete list of metamorphic and its behavior in the regular expression context:

character

description

/

The next character is marked as a special character, or a primary character, or a rearward reference, or an octal escape. For example, 'n' matches characters "n". '/ n' matches a newline. Sequence '//' Match "/" and "match" (".

^

Match the start position of the input string. If the multiline property of the regexp object is set, ^ also matches the location after '/ n' or '/ r'.

$

Match the end position of the input string. If the multiline property of the Regexp object is set, the $ also matches the position before '/ n' or '/ r'.

*

Match the previous sub-expression zero or multiple times. For example, ZO * can match "Z" and "ZOO". * Equivalent to {0,}.

Match the previous sub-expression once or multiple times. For example, 'ZO ' can match "ZO" and "ZOO" but cannot match "Z". Equivalent to {1,}.

?

Match the previous sub-expression zero or once. For example, "Do (ES)" can match "do" in "do" or "does". Is equivalent to {0,1}.

{n}

n is a non-negative integer. Match the determined N times. For example, 'o {2}' does not match 'o' in "Bob", but can match two O in "Food".

{n,}

n is a non-negative integer. At least n times. For example, 'o {2,}' cannot match 'O' in "Bob", but can match all O in "fooOOD". 'o {1,}' is equivalent to 'o '. 'o {0,}' is equivalent to 'o *'.

{n, m}

M and N are non-negative integers, where n <= m. Match at least n times and matched M times. "o {1, 3}" will match the top three O in "foooood". 'o {0,1}' is equivalent to 'o?'. Please note that there is no space between commas and two numbers.

?

When the character is tightly followed by any other restriction (*, ,?, {N}, {n,}, {n, m}), the matching mode is non-greedy. Non-greedy patterns match the search for strings as little as possible, and the default greed mode is as many as possible to match the search string. For example, for the string "OOOO", 'o ?' Will match a single "O", and 'o ' will match all 'o'. .

Match any individual characters other than "/ n". To match any characters including '/ n', use the mode of '[./n]'.

(Pattern)

Match Pattern and get this match. The acquired matches can be obtained from the generated Matches, using the Submatches collection in VBScript, using $ 0 ... $ 9 properties in Visual Basic Scripting Edition. To match the bracket characters, use '/ (' or '/)'.

(?: pattern)

Matching Pattern but does not acquire matching results, that is, this is a non-acquired match, not for storage for storage. This is useful to use the "or" character (|) to combine a pattern. For example, 'industr (?: Y | iES) is a smale of' Industry | Industries'.

(? = pattern)

Positive summation, match the lookup string at any string of Pattern. This is a non-acquisition match, that is, the match does not need to be used later. For example, 'Windows (? = 95 | 98 | NT | 2000)' Map "Windows" in Windows 2000, but does not match "Windows" in "Windows 3.1". It is not consumed by the character, that is, after a match occurs, start the next matching search immediately after the last match, not starting from the character containing the pre-check.

(?! Pattern)

Negative forecasts, match the lookup string at any string of NEGATIVE LOOKAHEAD MATCHES THE SEARCH STRING AT Any Point Where A STRING NOT Matching Pattern. This is a non-acquisition match, that is, the match does not need to be used later. For example, 'Windows (?! 95 | 98 | NT | 2000) "can match" Windows "in Windows 3.1, but cannot match" Windows "in" Windows 2000 ". The forecast does not consume characters, that is, after a match occurs, start the next matching search immediately after the last match, instead of starting from the character included in the queue

X | Y

Match X or Y. For example, 'Z | Food' can match "z" or "food". '(z | f) OOD' matches "Zood" or "Food".

[xyz]

Character collection. Match any of the included characters. For example, '[abc]' can match 'a' in "Plain".

[^ xyz]

Negative character set. Match any of the characters that are not included. For example, '[^ ABC]' can match 'P' in "Plain". [a-z]

Character range. Match any of the characters within the specified range. For example, '[a-z]' can match any lowercase alphabetic characters in the 'A' to 'Z' range.

[^ a-z]

Negative character range. Match any of any characters that are not within the specified range. For example, '[^ a-z]' can match any of any characters that are not in the 'A' to 'Z'.

/ B

Match a word boundary, that is, the location of the words and spaces. For example, 'er / b' can match 'ER' in "Never", but do not match 'Er' in "Verb".

/ B

Match the non word boundary. 'ER / B' can match 'Er' in "Verb", but cannot match 'Er' in "Never".

/ cx

Match the control character indicated by x. For example, / cm matches a Control-M or an Enterprise. The value of x must be one of A-Z or A-Z. Otherwise, the C is treated as a primary 'c' character.

/ d

Match a numeric character. Equivalent to [0-9].

/ D

Match a non-digital character. Equivalent to [^ 0-9].

/ f

Match a change page. Equivalent to / x0c and / cl.

/ N

Match a newline. Equivalent to / x0a and / cj.

/ r

Match a carriage return. Equivalent to / X0D and / cm.

/ s

Match any blank characters, including spaces, tabs, change, and more. Equivalent to [/ f / n / r / t / v].

/ S

Match any non-blank character. Equivalent to [^ / f / N / R / T / V].

/ t

Match a tab. Equivalent to / x09 and / ci.

/ v

Match a vertical tab. Equivalent to / x0b and / ck.

/ w

Match any word characters including underscore. Equivalent to '[A-ZA-Z0-9_]'.

/ W

Match any non-word characters. Equivalent to '[^ a-za-z0-9_]'.

/ xn

Match N, where n is a hexadecimal escape value. The hexadecimal escape value must be a determined two numbers long. For example, '/ x41' matches "a". '/ x041' is equivalent to '/ x04' & "1". ASCII coding can be used in regular expressions. .

/ NUM

Match Num, where NUM is a positive integer. References to the acquired match. For example, '(.) / 1' matches two consecutive identical characters.

/ N

Identifies an octal escape value or a backward reference. If the sub-expression of at least N before / N, n is a backward reference. Otherwise, if n is an octal number (0-7), then n is an eight-input escape value.

/ nm

Identifies an octal escape value or a backward reference. If the / nm has at least IS Preceded by Least NM acquired a sub-expression, the nm is a backward reference. If there is at least n acquisitions before / nm, then n is a rear reference reference to the text M. If the previous conditions are not satisfied, if n and m are octal numbers (0-7), the / nm will match the eight-way escape value Nm.

/ NML

If N is an octal number (0-3), and M and L are eight-input numbers (0-7), match the eight-encentric escape value NML.

/ UN

Match N, where N is a Unicode character represented by four hexadecimal numbers. For example, / u00A9 matches copyright symbol (?).

转载请注明原文地址:https://www.9cbs.com/read-65355.html

New Post(0)