I. Qualifier:A qualifier provides a simple method to specify the number of times a specific character or character set can appear repeatedly. The qualifier always references the pattern before the qualifier (left), usually a single character, unless you create a pattern group using parentheses. (1) Non-display qualifier
1, |
*The description "appears 0 or multiple times ". |
2, |
+, The description "appears one or more times ". |
3, |
?, The description "appears 0 or 1 time ". |
(2) Explicit delimiters The explicit qualifier uses braces {n, m} and their numeric values to indicate the upper and lower limits of the number of occurrences of the pattern. If only one number is specified, it indicates the maximum number of times. For example,X {5}Will match exactly 5 x characters (XXXXX), If the number is followed by a comma, suchX {5 ,}To match any x characters that appear more than 4 times. Ii. metacharacters .Metacharacter is the simplest but most commonly used character. It can match any single character. If you want to specify certain modes that can contain any combination of characters, it is very useful to use periods, but it must be within a specific length range. ^Metacharacters can specify the start of a string (or line. $Metacharacters can specify the end of a string (or line. By adding these characters to the start and end of the mode, you can force the mode to match only the exact matching input string. If^Metacharacters are used in square brackets.[]The start of the specified character class has a special meaning. After the specific content. \(Backslash) metacharacters can be used to escape characters based on special meanings, or to specify instances of pre-defined metacharacters. For more information, see. To include text-style metacharacters in a regular expression, you must use a backslash to "escape ". For example, to match a string starting with "C: \", you can use:^ C :\\. Note: Use^Metacharacters indicate that the string must start with this mode, and then escape the text backslash with the backslash. |(PIPE) metacharacters are used to specify alternately, especially to specify "this" or "this" in the mode ". For example,A | BWill match any input content that contains "A" or "B", which is similar to the character class[AB]Very similar. ()Parentheses are used to group the mode. It allows a qualifier to appear multiple times in a full mode. To facilitate reading, or to match specific input parts separately, you may be allowed to analyze or reset the format. Iii. character classes: The character class is the "mini" language in the regular expression, in square brackets[]. When you use a character class in an expression, you can use any one of the characters at this position of the mode (but only one character can be used, unless a qualifier is used ). Note that you cannot use a character class to define a word or mode. You can only define a single character. Use a hyphen in parentheses-To define the character range. A hyphen has a special meaning in the character class (not in a regular expression, so it cannot be called a regular expression metacharacter accurately ), and only when the hyphen is not the first character, the hyphen has a special meaning in the character class. To use a hyphen to specify any numeric value, you can use[0-9]. The same is true for lowercase letters.[A-Z], Uppercase letters can be used[A-Z]. The definition range of a hyphen depends on the character set used. Therefore, the order in which characters appear in (for example) ascii or Unicode tables determines the characters included in the range. If you need to include a hyphen in the range, specify it as the first character. For example:[-.?]Match any of the four characters (note that the last character is a space ). Note that regular expression metacharacters are not specially processed in character classes, so these metacharacters do not need to be escaped. Given that character classes are a language separate from other regular expression languages, character classes have their own rules and syntax. If you use characters^As the first character of the character class, this class is denied. It can also match any character other than the character class members. Therefore, to match any non-Vowel character, you can use the character class[^ Aaeeiioouu]. Note: To deny a hyphen, use the hyphen as the second character of the character class, as shown in figure[^-]. Remember,^The role of a character class in the regular expression mode is completely different from that in the character class. 4. predefined set metacharacters
| Metacharacters |
Equivalent character class |
\ |
Matching ringtone (alert); \ u0007 |
\ B |
Match the word boundary outside the character class, which matches the unsigned character, \ u0008 |
\ T |
Matched tab, \ u0009 |
\ R |
Match carriage return, \ u000d |
\ W |
Match vertical tabs, \ u000b |
\ F |
Match the newline, \ u000c |
\ N |
Match new line, \ u000a |
\ E |
Matching escape character, \ u001b |
\ 040 |
Matches three octal ASCII characters. \ 040 indicates space (32 in decimal format ). |
\ X20 |
Use a two-digit hexadecimal number to match ASCII characters. In this example, \ x2-indicates space. |
\ CC |
Matches ASCII control characters. In this example, It is Ctrl-C. |
\ U0020 |
Use a 4-digit hexadecimal number to match Unicode characters. In this example, \ u0020 is a space. |
\* |
It does not mean that any character of the pre-defined character class is treated only as this character. Therefore,\*Equivalent\ X2a(It is text *, not * metacharacters ). |
\ P {name} |
Match any character in the named character class "name. Supports Unicode groups and block ranges. For example, ll, Nd, Z, isgreek, isboxdrawing, and SC (currency ). |
\ P {name} |
Match the text not included in the named character class "name. |
\ W |
Match any word character. For non-Unicode and ecmascript implementations, this is equivalentA-za-z_0-9. In Unicode categories, this is equivalent[\ P {ll} \ P {Lu} \ P {lt} \ P {lo} \ P {nd} \ P {PC}]. |
\ W |
The negative value of \ W is equivalent to the ecmascript compatible set.[^ A-za-z_0-9]Or UNICODE character category[^ \ P {ll} \ P {Lu} \ P {lt} \ P {lo} \ P {nd} \ P {PC}]. |
\ S |
Match any characters in the blank area. Equivalent to the Unicode character class[\ F \ n \ r \ t \ v \ x85 \ P {z}]. If you use the ecmascript option to specify the ecmascript compatibility mode, \ s is equivalent[\ F \ n \ r \ t \ v](Note the leading space ). |
\ S |
Match any non-blank area characters. Equivalent to the Unicode character category[^ \ F \ n \ r \ t \ v \ x85 \ P {z}]. If you use the ecmascript option to specify the ecmascript compatibility mode, \ s is equivalent[^ \ F \ n \ r \ t \ v](Note the space after ^ ). |
\ D |
Match any decimal number. In the ecmascript mode[\ P {nd}]Non-Unicode[0-9]. |
\ D |
Match any non-decimal number. In the ecmascript mode[\ P {nd}]Non-Unicode[^ 0-9]. |
V. Create and use the regularexpressions class in Asp.net (see 《Use Regular Expression in Asp.net (2)" |