Regular expression

zhaozj2021-02-16  58

/: Mark the next character as a special character or a literal value. For example, "N" matches the character "n". "/ N" matches the laundry. Sequence "//" with "/" match, "/ (" matches ".

^: Match the start position of the input.

$: Match the end of the input.

*: Match the previous character zero or several times. For example: "ZO *" can match "Z", "ZOO".

: Match the previous character once or more. For example: "ZO " can match "ZOO" but do not match "Z".

?: Match the previous character zero or once. For example: "a? Ve?" Can match "VE" in "Never".

.: Match any character other than changing line characters.

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

{n}: n is a non-negative integer. The match is just n times. For example: "O {2}" cannot match "O" in "Bob", but can match the first two o "foooood".

{n,}: n is a non-negative integer. Match at least n times. For example: "o {2,}" does not match "O" in "Bob", but matches all O in "foooood". "O {1,}" is equivalent to "o ". "O {0,}" is equivalent to "o *".

{n, m}: m and n are non-negative integers. Match at least n times, up to M times. For example: "O {1,3}" matches the top three O in "foooood". "O {0,1}" is equivalent to "o?".

[XYZ]: A character set. Match one of the characters in parentheses. For example: "[ABC]" matches "A" in "Plain".

[^ XYZ]: A negative character set. Match any character in this parentheses. For example: "[^ ABC]" can match "P" in "PLAIN".

[A-Z]: Represents characters within a range. Match with any character in the specified interval. For example: "[A-Z]" matches "A" and "Z" any lowercase letters characters.

[^ m-z]: Negate character interval. Match with characters that are not within the specified interval. For example: "[m-z]" matches any character that is not in "M" to "Z".

/ B: Match the boundary of the word, that is, the position between words and spaces. For example: "ER / B" matches "er" in "Never", but does not match "ER" in "Verb".

/ B: Match with non-word boundary. "EA * R / B" matches "EAR" in "NEVER EARLY".

/ d: Match with a numeric character. Equivalent to [0-9].

/ D: Match with non-digital characters. Equivalent to [^ 0-9].

/ f: Match with the pacharge.

/ N: Match with the wrap character.

/ R: Match with the carriage return character.

/ S: Match with any blank character, including spaces, tabs, pagings, and the like. Equivalent "[/ f / n / r / t / v]".

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

/ T: Matching the player.

/ V: match the vertical tab.

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

/ W: Match with any non-word character. Equivalent "[^ a-za-z0-9]".

/ NUM: Match NUM, where NUM is a positive integer. Quote Back to remember the match. For example: "(.) / 1" matches two consecutive identical characters.

/ N: Match N, where N is an octaves. The octal modulation value must be 1, 2 or 3 numbers long.

For example, "/ 11" and "/ 011" matches a tab. "/ 0011" equivalent to "/ 001" and "1". The octal exchange value must not exceed 256. Otherwise, only the first two characters are considered part of the expression. Allows the use of the ASCII code in the regular expression.

/ xn: Match N, where N is a hexadecimal modified value. The hexadecimal modified value must be long for two numbers.

For example, "/ x41" matches "A". "/ X041" equivalent to "/ x04" and "1". Allows the use of the ASCII code in the regular expression.

RegularExpressionValidator has two main properties to verify validity. ControlTovAlidate contains a value verified. Return the value in the text box. If the ControlTovAlidate "TextBox1" ValidationExpression contains a regular expression for verification. For example, a legal email address should at least satisfy the following conditions:

1. There must be one and only one symbol "@"

2. The first character must not be "@" or "."

3. "@." Or. @ Is not allowed

4. The end may not be a character "@" or "."

So according to the above principles and the grammar in the above table, we get the needs template as follows:

"^ / W ((((((((((W )) * / [A-ZA-Z0-9] (/. | -) [A-ZA-Z0-9] ) * / [A-ZA-Z0-9] $ "

@ "^ (1 [/W-/.] 1) @ (2 (3 /[0-9]:1, 3 ►.[0-9]: 1, 3 }/ .[0-9 ] {1,3} /. 3) | (4 (5 [/W-] /.5 ) 4) 2) (6 [A-ZA-Z] {2, 4} | [0-9] {1,3}) (/]? 6) $ "

*********************************************************** *********

Regular expression

/: Mark the next character as a special character or a literal value. For example, "N" matches the character "n". "/ N" matches the laundry. Sequence "//" with "/" match, "/ (" matches ".

^: Match the start position of the input.

$: Match the end of the input.

*: Match the previous character zero or several times. For example: "ZO *" can match "Z", "ZOO".

: Match the previous character once or more. For example: "ZO " can match "ZOO" but do not match "Z".

?: Match the previous character zero or once. For example: "a? Ve?" Can match "VE" in "Never".

.: Match any character other than changing line characters.

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

{n}: n is a non-negative integer. The match is just n times. For example: "O {2}" cannot match "O" in "Bob", but can match the first two o "foooood".

{n,}: n is a non-negative integer. Match at least n times. For example: "o {2,}" does not match "O" in "Bob", but matches all O in "foooood". "O {1,}" is equivalent to "o ". "O {0,}" is equivalent to "o *".

{n, m}: m and n are non-negative integers. Match at least n times, up to M times. For example: "O {1,3}" matches the top three O in "foooood". "O {0,1}" is equivalent to "o?".

[XYZ]: A character set. Match one of the characters in parentheses. For example: "[ABC]" matches "A" in "Plain".

[^ XYZ]: A negative character set. Match any character in this parentheses. For example: "[^ ABC]" can match "P" in "PLAIN".

[A-Z]: Represents characters within a range. Match with any character in the specified interval. For example: "[A-Z]" matches "A" and "Z" any lowercase letters characters.

[^ m-z]: Negate character interval. Match with characters that are not within the specified interval. For example: "[m-z]" matches any character that is not in "M" to "Z".

/ B: Match the boundary of the word, that is, the position between words and spaces. For example: "ER / B" matches "er" in "Never", but does not match "ER" in "Verb".

/ B: Match with non-word boundary. "EA * R / B" matches "EAR" in "NEVER EARLY".

/ d: Match with a numeric character. Equivalent to [0-9]. / D: Match with non-digital characters. Equivalent to [^ 0-9].

/ f: Match with the pacharge.

/ N: Match with the wrap character.

/ R: Match with the carriage return character.

/ S: Match with any blank character, including spaces, tabs, pagings, and the like. Equivalent "[/ f / n / r / t / v]".

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

/ T: Matching the player.

/ V: match the vertical tab.

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

/ W: Match with any non-word character. Equivalent "[^ a-za-z0-9]".

/ NUM: Match NUM, where NUM is a positive integer. Quote Back to remember the match. For example: "(.) / 1" matches two consecutive identical characters.

/ N: Match N, where N is an octaves. The octal modulation value must be 1, 2 or 3 numbers long. For example, "/ 11" and "/ 011" matches a tab. "/ 0011" equivalent to "/ 001" and "1". The octal exchange value must not exceed 256. Otherwise, only the first two characters are considered part of the expression. Allows the use of the ASCII code in the regular expression.

/ xn: Match N, where N is a hexadecimal modified value. The hexadecimal modified value must be long for two numbers.

For example, "/ x41" matches "A". "/ X041" equivalent to "/ x04" and "1". Allows the use of the ASCII code in the regular expression.

RegularExpressionValidator has two main properties to verify validity. ControlTovAlidate contains a value verified. Return the value in the text box. If the ControlTovAlidate "TextBox1" ValidationExpression contains a regular expression for verification.

For example, a legal email address should at least satisfy the following conditions:

1. There must be one and only one symbol "@"

2. The first character must not be "@" or "."

3. "@." Or. @ Is not allowed

4. The end may not be a character "@" or "."

So according to the above principles and the grammar in the above table, we get the needs template as follows:

"^ / W ((((((((((W )) * / [A-ZA-Z0-9] (/. | -) [A-ZA-Z0-9] ) * / [A-ZA-Z0-9] $ "

*********************************************************** ****

-, "^" head match

^ Front represents a string that starts with "Front".

Second, "$" tail match

TAIL $ indicates a string ending with "tail".

Third, escape sequence

All essential sequences are used "/". Such as "^", "$", " ", "(") "has special significance in the expression, so in the regular expression" / ^ "," / $ "," / ","/(","/)"To represent.

Fourth, character cluster

[AZ] Match uppercase characters; [AZ] matching writing characters; [A-ZA-Z] matches all characters; [0-9] matches all numbers; [/./-/ ] match all the sentence, minus, and add Number; [^ AZ] In addition to the character other than lowercase letters; ^ [^ AZ] The first character cannot be lowercase letters; [^ 0-9] In addition to all characters outside the number;

Five, repeat

^ a {4} $ represents AAAA; ^ a {2, 4} represents AA, AAA or AAAA; ^ a {2,} represents more than two A strings;. {2} represents all two characters; Next, two common examples are given:

1, Email verification

Claim:

(1) There must be a "@"

(2) The string behind "@" contains at least one "."

(3) "@" front and back strings consist of one or more letters, numbers, underscores or minus prices

According to these rules, you can have the following regular expressions:

^ [A-ZA-Z0-9 _ / -] {1,} @ [A-ZA-Z0-9 _ / -] {1,} /. [A-ZA-Z0-9 _ / -.] {1,} $

or:

/ w ([- .]/w ) *@/w ([-.]/w )**/W ([-.]/w ) *

2, the verification of the phone number

Claim:

(1) Composition by the phone number, "(", ")" and "-"

(2) The phone number is 3 to 8 digits

(3) If there is a zone code in the phone number, the area code is three or four digits.

(4) Area code "(", ")" or "-" and other parts

(5) The mobile phone number is 11 or 12 digits, if it is 12 digits, then the first bit is 0

(6) 11 first and second bit of mobile phone number "13"

(7) The second and third bit of the 12 mobile phone number are "13"

According to these rules, you can have the following regular expressions:

(^ [0-9] {3,4} / - [0-9] {3,8} $) | (^ [0-9] {3,8} $) | (^ / ([0-9 ] {3,4} /) [0-9] {3,8} $) | (^ 0 {0, 1} 13 [0-9] {9} $)

/

Marks the next character, a literal, a backreference, or an octal escape. For example, 'n' matches the character "n". '/ N' matches a newline character. The sequence '//' matches "/" and "/ (" matches ".

^

Matches the position at the beginning of the regexp Object's multiline property is set, ^ also matches the position following '/ n' or '/ r'.

$

Matches the position at the end of the input string. If The Regexp Object's Multiline Property Is Set, $ Also Matches The position preceding '/ n' or '/ r'.

*

Matches The Preceding Subexpression Zero or More Times. For example, zo * matches "z" and "zoo". * Is equivalent to {0,}.

Matches the preceding subs. For example, 'zo ' matches "zo" and "zoo", but not "z". Is equivalent to {1,}.?

Matches The Preceding SubExpression Zero or One Time. For Example, "Do (ES)?" Do "or" does ".? Is Equivalent to {0,1}

{n}

N IS A Nonnegative INTEGER. Matches Exactly N Times. for Example, 'O {2}' Does Not Match The 'O' in "Bob," But Matches The Two O's in "Food".

{n,}

N is a nonnegative INTEGER. MATCHES AT Least N Times. for Example, 'O {2,}' Does Not Match The "O" in "bob" and matches all the o's in "fooood". 'o {1,}' Is Equivalent to 'o '. 'o {0,}' is equivalent to 'o *'.

{n, m}

M and N Are Nonnegative INTEGERS, WHERE N <= m. matches at Least N And at Matches. for Example, "O {1,3}" matches the first three o's in "foooood". 'o {0,1 } 'Is Equivalent to' o? '. Note That You Cannot Put a Space Between The Comma and The Numbers.

.

Matches Any Single Character Except "/ n". To match any character incruding the '/ n', Use a pattern such as '[./n]'.

X | Y

Matches Either X Or Y. For Example, 'Z | Food' matches "z" or "food". '(Z | f) ood' matches "zood" or "food".

[xyz]

A character set. Matches any one of the enclosed character example, '[abc]' matches the 'a' in "plain".

[^ xyz]

A NEGATIVE CHARACTER SET. Matches any character not enclosed. For example 'matches the' p 'in "plain".

[a-z]

A Range of Characters. Matches Any Character in The Specified Range. For Example, '[A-Z]' Matches Any LowerCase Alphabetic Character in The Range 'A' THROUGH 'Z'. [^ A-z]

A NEGATIVE RANGE CHARACTERS. Matches Any Character Not in The Specified Range. For Example, '[^ a-z]' matches any character not in the range 'a' through 'z'.

/ d

Matches a Digit Character. Equivalent TO [0-9].

/ D

Matches a Nondigit Character. Equivalent TO [^ 0-9].

/ w

Matches Any Word Character Including Underscore. Equivalent To '[A-ZA-Z0-9_]'.

/ W

Matches Any Nonword Character. Equivalent to '[^ A-ZA-Z0-9_]'.

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

New Post(0)