-, "^" head match ^ Front Indicates a string that starts with "Front". Second, the "$" tail match TAIL $ indicates the string ending with "tail". Third, all escape sequences all the escape sequences are "/" head. Such as "^", "$", " ", "(") "has special significance in the expression, so in the regular expression" / ^ "," / $ "," / ","/(","/)"To represent. Fourth, the character cluster [AZ] matches lowercase characters; [AZ] matching the writing character; [A-ZA-Z] matches all characters; [0-9] matches all numbers; [/./-/ ] Match all the sentences, Dimensional and plus sign; [^ AZ] In addition to a character other than lowercase letters; ^ [^ AZ] The first character cannot be lowercase letters; [^ 0-9] In addition to all characters outside the number; five, repetition ^ 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's verification requirements: (1) must include a string behind "@" contains at least one "." (3) "@" front and back strings by one or one The above letters, numbers, underscores or minus, according to these rules, the following regular expressions can be related to 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 requirements of the phone number: (1) Phone number is numbered, "(", ")" and "-" Composition (2) The phone number is 3 to 8 bits (3) If the phone number contains a zone number, then Area number (",") "or" - "and other parts (5) The mobile phone number is 11 or 12 bits, if it is 12 bits, then the first bit is 0 (6) 11-bit mobile phone number, the first bit and the second bit of "13" (7) 12-bit mobile phone number, the third bit is "13" according to these rules, can be 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} $) ----- ------------------------------- Date 20 / D {2} ((0 [1-9]) (1 [0-2])) (-) ((0 [1-9]) | ([1-2] [0-9]) | (3 [0-1])) (t | / s (([0-1] [0-9]) | (2 [0-3])): ([0-5] [0-9]): ([0-5] [0-9])
Format 2004-05-06 14:00:00 ([0-9] {4}) - ([0-9] {1, 2}) - ([0-9] {1, 2})
-------------------------- Digital, Letters, Underline ^ [0-9A-ZA-Z_] * $ ^ [A-ZA-Z0 -9] * $ -------------------- can only enter 2 ~ 10 Chinese characters ^ [/ u4e00- / u9fa5] {2,10} $ ---------------------- 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:
JScript VBScript Match / ^ / [/ T] * $ / "^ / [/ t] * $" matches a blank line. // D {2} - / d {5} / "/ d {2} - / d {5}" Verify that one ID number is composed of a 2-digit, a hyphen, and a 5-digit. /< (.*)>. (*)>. * // 1> "matches an HTML tag.
The table below is a complete list of metamorphic and its behavior in the regular expression context:
Character Description / Tags the next character as a special character, or a primary character, or a backward reference, or an octave. For example, 'n' matches characters "n". '/ n' matches a newline. Sequence '//' match "/" "/ (" matches "(". ^ Match the input string of the start position. If the multiline property of the regexp object is set, ^ also matches '/ n' or '/ r' The next location. $ Match the end position of the input string. If the multiline property of the regexp object is set, $ 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 more. For example, 'ZO ' can match "ZO" and "ZOO" However, it cannot match "Z". Equivalent to {1,}. • Match the previous sub-expression zero or once. For example, "Do (es)" can match "do" or "does" "" " Do ".? Is equivalent to {0,1}. {n} n is a non-negative integer. Match the N times. For example, 'o {2}' does not match" Bob "'o', but can Match two O. {n,} n is a non-negative integer. At least n times. For example, 'o {2,}' does not match 'O' in "Bob", but can match " All O.'o {1,} 'is equivalent to' o * 'in FooOOD.