2、 Antonym character
3、 Escape character
4、 Repeated matching
5、 Group / capture
6、 Greed and inertia
Matches phone numbers that start with 11n, 12n or 1nnn, followed by – 7-8 digits.
Recommend a tool to represent regularization graphically
The above example is translated into a graphical representation as follows:
Explain what this regular means
(?:...)?(.*)Look at the two outermost brackets. The first one is a non trapping bracket. The? Sign acts on this bracket. The second bracket is capture type and matches multiple arbitrary characters.
([^:;(*):This is a catch bracket and a character: sign
[^:;(*Capture type brackets also contain a character group (()) and a * sign. In the character group, multiple characters except; ([are matched)
A method of telephone number extraction is realized with JS.
For example: “1852145998, 020-888-999845, test 021 – 85421987, 19865754” and the result should be [1852145998, 020-888-999845, 021 – 85421987, 19865754]
Var STR = 1852145998 020-888-999845 test 021-85421987, 19865754 "; var reg=/(1\d+)|(0[0-9\s\-]+)/g; console.log(str.match(reg));
. test (string): returns a Boolean value indicating whether the incoming string matches the regular (starting from where indicated by the lastindex property)
. exec (string): returns an array containing matching results (with two additional attributes: input represents the target string of the search, that is, the parameter passed in to the exec method; index indicates the position of the matching result in the target string) or null (cannot match). Even if the G option is added to the regular, continue the search by calling the method of the same regular object multiple times (each search will continue from where indicated by the lastindex property). If the search is completed, lastindex is automatically set to 0). If the G option is not added, the result is the same several times. If no match is found, null is returned and the lastindex of the regular object is automatically set to 0
Related methods of string object:
String. Match ()
String. Search ()
String. Split ()
String. Replace ()
For more information, please refer to the chapter regexp.