//url
|
Symbol |
Meaning |
Common usage |
\ | Change the meaning, that is, usually the characters after "\" are not interpreted according to the original meaning. For example, /b/ matches the character "b". When a backslash is added in front of b, /\b/, the meaning is changed to match a word boundaries. |
高 |
- |
Reduction of regular expression function characters, such as "" matches the metacharacter before it 0 or more times times, /a/ will match a, aa, aaa. After adding "\", /a*/ will only match "a*". |
高 |
^ |
Matches an input or the beginning of a line, /^a/ matches "an A", but does not match "An a " |
高 |
$ |
matches an input or the end of a line, /a$/ matches "An a", but does not match "an A” |
高 |
* |
matches the preceding metacharacter 0 or more times, /ba*/ will match b,ba,baa, baaa |
高 |
##+ | matches the preceding metacharacter 1 or more times, /ba*/ will match ba, baa, baaa | Low |
? | matches the preceding metacharacter 0 or 1 times, /ba*/ will match b,ba | low |
(x) | Matches x and saves x in a variable named
9
| Low |
x|y | Match x or y | 中 |
{n} | Exactly match n times |
|
{n,} | Match more than n times | 中 |
{n,m} | match n-m times | 中 |
##[ xyz]
Character set (character set), matches any character (or metacharacter) in this set |
高 |
|
[ ^xyz]
Does not match any character in this set |
High |
| ##[\b]
matches a return The case character | 中 |
##\b |
matches the boundary of a word
中 |
|
\B |
Match a non-boundary word
中 |
|
\cX |
Here, X is a control character, /\cM/ matches Ctrl-M
|
|
\d |
matches an alphanumeric character, /\d/ = /[0-9] /
高 |
|
\D |
matches a non-alphanumeric character, /\D/ = /[^0-9]/
High |
|
\n |
Matches a newline character
中 |
|
\r |
Matches a carriage return character
in |
|
\s |
Matches a blank character, including \n, \r, \f ,\t,\v, etc.
|
\S |
in |
matches a non-whitespace character, equal to /[^\n\f\r \t\v]/
中 |
|
\t |
matches a tab character
中 |
|
\v |
matches a double tab
中 |
|
\w |
matches A character that can form a word (alphanumeric, this is my free translation, including numbers), including underscores, such as [\w] matching 5 in "$5.98", which is equal to [a-zA-Z0-9]
高 |
| ##\W | matches a character that cannot form a word, such as [\W] matching "
|
, equal to [^a-zA-Z0-9]高
|
Create a regular description object: var pattern = /\w/; or var pattern = new RegExp(/\w/)
Test whether the string is regular: pattern.test(0) Note: The previously created regular pattern matches the text between 0-9a-zA-Z, and returns true if they all match
17 commonly used regular expressions:
Expression |
Use |
##^\\d+$
| //Non-negative integer (positive integer + 0) |
^ [0-9]*[1-9][0-9]*$
| //Positive integer |
^((- \\d+)|(0+))$
| //Non-positive integer (negative integer + 0) |
##^-[0 -9]*[1-9][0-9]*$
//Negative integer |
|
^-?\\d+ $
//Integer |
|
##^\\d+(\\.\\d+)?$
//Non-negative floating point number (positive floating point number + 0) |
|
^(([0-9]+\\.[0-9]*[1- 9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9 ][0-9]*))$
//Positive floating point number |
|
^((-\\d+(\\. \\d+)?)|(0+(\\.0+)?))$
//Non-positive floating point number (negative floating point number + 0) |
|
^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1 -9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
//Negative floating point number |
|
^(-?\\d+)(\\.\\d+)?$
// Floating point number |
|
^[A-Za-z]+$
//String consisting of 26 English letters |
|
^[A-Z]+$
//A string consisting of 26 uppercase English letters |
|
^[a-z]+$
//A string consisting of 26 lowercase English letters |
|
^[ A-Za-z0-9]+$
//A string consisting of numbers and 26 English letters |
| ##^\\ w+$
//A string consisting of numbers, 26 English letters or underscores
|
| ^[\\w-]+( \\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$
//email address
|
| ^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+) *))*(\\?\\S*)?$
//url
| ##Related recommendations: |
JS regular expressions detailed explanation
The use and basic syntax of JS regular expressions
Summary of the key points of JS regular expressions
|