1. Regular Expression RegularExpretion)
It is a "string" used to describe "string features" and is written according to special rules. It is widely used in modern programming languages.
2. For example:
1) How do I describe strings with "Numbers?
2) how to determine if the string is a valid ID card number, email format, date and time format ....?
3) check whether a character string contains a specific combination of letters, regardless of case?
4) judgment .....
The above are the application of regular expressions.
3. Regular object
In javascript, use the RegExp regular class) to describe a regular string and remember that it is not a string object ).
The new method is as follows:
1) r1 = newRegExp ('regularization ');
2) r2 =/regular expression/igm;
With this object, we can make a big difference, but, wait, regular-expression rules ???
4. Regular Expression rules:
The above regular expression can contain the following characters:
1) a common character or string, such as "a, 8, and China", indicates a single-word match, that is, a string matches exactly what is written.
For example, m =/abc/; the table-type target string contains abc, such as dkdfdabcdfwer.
2) number of characters in the table:
A) "a *" indicates 0 to n a numbers, such as "abc", "bcaadea", "xdee"
B) "a +" indicates 1-N
C) "? "Indicates 0 or 1
3) "^" at the beginning of the table, "$" at the end of the table, such as "^ a", which indicates a string starting with a, "B $ ", string ending with B
4) special characters
| Metacharacters |
Description |
| . |
Searches for a single character, except for line breaks and line Terminators. |
| \ W |
Search for word characters. |
| \ W |
Searches for non-word characters. |
| \ D |
Search for numbers. |
| \ D |
Searches for non-numeric characters. |
| \ S |
Search for blank characters. |
| \ S |
Searches for non-blank characters. |
| \ B |
Match the word boundary. |
| \ B |
Match non-word boundary. |
| \ 0 |
Search for NUL characters. |
| \ N |
Find a line break. |
| \ F |
Find a break. |
| \ R |
Find the carriage return. |
| \ T |
Search for tabs. |
| \ V |
Search for vertical tabs. |
| \ Xxx |
Search for characters specified by octal xxx. |
| \ Xdd |
Search for the characters specified by dd in hexadecimal notation. |
| \ Uxxxx |
Find the Unicode characters specified by the hexadecimal number xxxx. |
5) square brackets:
| Expression |
Description |
| [Abc] |
Find any character between square brackets. String with a, B, or c |
| [^ Abc] |
Search for any characters that are not in square brackets. |
| [0-9] |
Search for any number ranging from 0 to 9. |
| [A-z] |
Search for any characters from lowercase to lowercase. |
| A-Z |
Search for any characters from uppercase A to uppercase Z. |
| [A-z] |
Search for any characters from uppercase A to lowercase z. |
| (Red | blue | green) |
Find any specified options. String with red, blue, or green |
This article from the "Yu yu" blog, please be sure to keep this source http://johnyu.blog.51cto.com/7838287/1300322