Home > front end >  JavaScript regular expressions
JavaScript regular expressions

Time:09-21

JavaScript regular expression
Regular expressions: also known as the regular expression
English named Regular Expression, often abbreviated in the code for regex, RegExp or RE

Regular expressions are used to define some rules of the string, a computer can according to the regular expression, to check whether a string is conform to the rules, characters can conform to the rules are extracted from the content of the
Grammar: var variable=new RegExp (" regular expression ", "match the pattern");
Use the typeof check regular object, will return to the object
Var reg=new RegExp (" a "); This expression can be used to check whether a string containing the characters in a
In the constructor can pass a matching model as the second parameter
I ignore case
G global matching
The method of the regular expression:
The test ()
- use this method can be used to check whether a string in accordance with the rules of the regular expression
If conform to return true, otherwise it returns false
Use the literal to create a regular expression
Grammar: var variable=/regular expression matching mode
Create a regular expression, to check whether a string containing the letter
[] to use the brace said range
[ABC] is equivalent to a | b | c
[a-z] means to match all lowercase
[a-z] means to match all the capital letters
[a-z] means to match all of the letters (with case)
[0-9] means to match all digital
For example:

Print:
  • Related