How to use
1. Create an expression
Methods for creating regular expression classes in javascript:
var regex = new RegExp ("\\d{5}") or 2.var regex =/\d{5}/(Recommended)
/Expression/is the syntax provided specifically for simplifying regular expression writing in JavaScript, and regular expressions written in//are not escaped by the Tube escape character.
Methods for RegExp objects:
2. determine if the match
Test (STR) determines whether the string str matches the regular expression, equivalent to IsMatch
var regex =/[email protected]+/;
Alert (Regex.test ("[email protected]");
Alert (Regex.test ("ab.com"));
3. Get matching results
EXEC (str) makes a search match, and the return value is the matching result (*), which corresponds to C # in match () and matches ()
If EXEC () finds the matched text, it returns an array of results (exactly matched strings and the results of the extraction group). )。 Otherwise, NULL is returned. To extract multiple calls, exec () is similar to the matches () method repeatedly.
Note the global mode/...../g
In non-global mode, calling exec () equals match ();
Multiple calls in global mode equal to matches ()
---i ignore case
---m multi-line matching
Regular expressions in JavaScript