1] Regular characters commonly used character
special characters commonly used in regular expressions
| Character |
The |
Example |
| ^ |
Start of Match input |
/^this/matches "This is ..." |
| $ |
Match end of input |
/end$/matches "This is the end" |
| * |
Match 0 or more times |
/se*/matches "Seeee", also matches "se" |
| ? |
Match 0 or one time |
/ap?/matches "Apple" and "and" |
| + |
Match one or more times |
/ap+/matches "Apple" but does not match "and" |
| N |
Strictly Match n times |
/ap{2}/matches "Apple" but does not match "Apie" |
| {N,} |
Match n times or N extra times |
/ap{2,}/matches all p in "apple" and "appple", but does not match "Apie" |
| {N, m} |
Matches at least n times, up to M times |
/ap{2,4}/matches 4 p in "Apppppple" |
| . |
Any character other than line break |
/a.e/matches "ape" and "Axe" |
| [...] |
Any of the characters in square brackets |
/a[px]e/matches "ape" and "axe", but does not match "ale" |
| [^...] |
Any character except the character in square brackets |
/a[px]e/matches ale, but does not match ape, or axe |
| \b |
Words on the border |
\bno\ matches the first "no" in "none" |
| \b |
A word on a non-boundary |
\bno\ matches the second "no" in "none" |
| \d |
The number from 0-9 is equivalent to [0-9] |
/\d{3}/matches "123" in "123" |
| \d |
Any non-numeric character is equivalent to [^0-9] |
/\d{2,4}/matches ' now ' in ' Now ' in 123 |
| \w |
Match word characters (letters, numbers, underscores) equivalent to [a-za-z0-9_] |
/\w/matches "J" in JavaScript |
| \w |
Match non-word characters (not letters, numbers, underscores) |
/\w/matches "%" in "100%" |
| \ n |
Match a line break |
|
| \s |
A single white-space character |
|
| \s |
A single, non-whitespace character |
|
| \ t |
A tab |
|
| (x) |
Capturing parentheses |
Remember the characters that match |
2] As with other objects, there are direct quantities and regexp of objects.
1 // Regular Objects 2 var New REGEXP ("A\s+b"); 3 // Regular Direct Volume 4 /a\s+b/5// final match a B, or a B, but does not match AB
(not to be continued ...)
JavaScript Classic instances-Regular expressions