Application of regular expression

xiaoxiao2021-03-06  78

// Add by Wyn 2004-10-12 11:20:59

/ Refreshing

^ Match from the beginning

$ Matching from the end

* 0 times or multiple times the front character {0,}

1 or multiple matches the front character {1,}

? 0 times or 1 time matching front characters {0,1}

{n} matches n times (n = int && n> 0)

• When this character follows any other qualifiers (*, , {n}, {n,}, {n, m}), the matching mode is "non-greedy". "Non-greed" pattern matches search, as short strings as possible, and the default "greed" pattern matches the search, as long as possible strings. For example, in the string "OOOO", "O ?" Only matches a single "O", and "o " matches all "O".

Match any individual characters other than "/ n". To match any of the characters including "/ n", use the model such as "[/ s / s]".

(Pattern) Match Pattern and captures the matching sub-expression. You can use $ 0 ... $ 9 properties to retrieve capture matching from the result "match" collection. To match parentheses characters (), use "/ (" or "/)".

(?: pattern) Match Pattern but does not capture the matching sub-expression, ie it is a nonaptured match, not stored in the future. This is useful for the case of "or" character (|) combined mode components. For example, "Industr (?: Y | IES)" is a more economical expression than "Industry | Industries".

(? = pattern) Performs a sub-expression forward predicts the first search of the first search, which matches the string of the starting point of the string that matches Pattern. It is a nonaptured match, that is, it cannot capture the matching of future use. For example, "Windows (? = 95 | 98 | NT | 2000)" matches "Windows" in Windows 2000, but does not match "Windows" in "Windows 3.1". The predicts do not occupy characters, that is, after matching, the next matching search is followed by the previous match, not the character that makes up the first character.

(?! pattern) Execute a sub-expression that reverse predicts the first search, the expression matches the search string of the starting point that is not in the starting point of the string of Pattern. It is a nonaptured match, that is, it cannot capture the matching of future use. For example, "Windows (?! 95 | 98 | nt | 2000)" matches "Windows 3.1" in "Windows 3.1", but does not match "Windows" in Windows 2000. The predicts do not occupy characters, that is, after matching, the next matching search is followed by the previous match, not the character that makes up the first character.

X | Y matches X or Y. For example, "Z | Food" matches "Z" or "Food". "(Z | f) OOD" matches "Zood" or "Food".

[XYZ] character set. Match any of the characters contained. For example, "[ABC]" matches "A" in "Plain".

[^ xyz] reverse character set. Match any characters that are not included. For example, "[^ ABC]" matches "P" in "PLAIN".

[A-Z] character range. Match any characters within the specified range. For example, "[A-Z]" matches "A" to any lowercase letters within the "Z" range.

[^ a-z] reverse range character. Matching any characters not within the specified range. For example, "[^ a-z]" matches any character that is not in "a" to "z".

/ b matches a word boundary, namely the location between words and spaces. For example, "ER / B" matches "ER" in "Never" but does not match "ER" in "Verb".

/ B non-word matching. "ER / B" matches "ER" in "VERB", but does not match "ER" in "Never". / CX matches the control character indicated by X. For example, / cm matches a Control-M or an Enterprise. The value of x must be between A-Z or A-Z. If this is not the case, it is assumed that C is "C" character itself.

/ d numeric character match. Equivalent to [0-9].

/ D non-numeric character match. Equivalent to [^ 0-9].

/ f Change page matches. Equivalent to / X0c and / cl.

/ N displacement match. Equivalent to / x0a and / cj.

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

/ s Match any blank character, including spaces, tabs, change page, etc. Equivalent to [/ f / N / R / T / V].

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

/ t tatome match. Equivalent to / x09 and / ci.

/ v Vertical tab matches. Equivalent to / x0b and / ck.

/ W Match any word character, including underscore. Equivalent to "[A-ZA-Z0-9_].

/ W any non-word matching. Equivalent to "[^ a-za-z0-9_].

/ XN matches N, which is the N is a hex escape code. The sixteen-based escape code must be just two digits. For example, "/ x41" matches "A". "/ X041" is equivalent to "/ X04" & "1". Allows the use of ASCII code in the regular expression.

/ NUM matches NUM, and NUM here is a positive integer. To the reverse reference of the capture match. For example, "(.) / 1" matches two consecutive identical characters.

/ n identifies an octal escape code or reverse reference. If there is at least N capture sub-expression in front of / N, then n is a reverse reference. Otherwise, if n is an eight-input number (0-7), then N is an octal transfilling code.

/ Nm identifies an octal escaping code or reverse reference. If there is at least nm capture sub-expression in front of / Nm, then Nm is a reverse reference. If there is at least N capture in front of / Nm, then n is a reverse reference, followed by M. If the previous conditions do not exist, then when N and M are eight-input (0-7), / Nm matches the eight-way propagander NM.

/ Nml When N is an octal number (0-3), M and L are eight-input (0-7), match the eight-enthnate symbol NML.

/ UN matches N, where N is a Unicode character represented by four-bit hexadecimal number. For example, / u00A9 matches copyright symbol (©).

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

New Post(0)