JavaScript's regular expression basic knowledge summary, for learning regular expression of friends is a good basic primer material.
Meta character
^ $ . * + ? = ! : | \ / ( ) [ ] { }
The use of these symbols requires "\" to be transferred.
If you can't remember the punctuation that needs to be transferred, you can use the backslash "\" when using punctuation.
Simple Match
1. Direct volume/javascript/matches strings with "JavaScript" such as "JavaScript is an object-oriented scripting language"
2, []/[abc]/matches the character "a" or "B" or "C"
3, [^]/[^abc]/matches any character except A, B, c
4,. /./any character
5, \w/\w/any ASCII single character, equivalent to [a-za-z0-9]
6, \s/\s/blank character
7, \d/\d/number, equivalent to [0-9]
Repeat
1. {n,m}/[a]{3,5}/repeats at least n times, e.g. "AAA" or "AAAA" or "AAAAA"
2, {n,}/[a]{3,}/repeats at least n times, such as "AAA" or "AAAAA" or "aaaaaa" ...
3, {n}/[a]/{3} just matches n times, such as only "AAA"
4,? /[a]?/0 or 1 times
5, +/[a]+/1 or more times
6, */[a]*/0 or more times
Select, group
1, | /a|b/Select to match "a" or "B"
2, ()/(ABC) +/grouping, matching "abc" or "Abcabc" ...
location
1, ^/^a/start with "a", such as "AB" or "abc" ...
2, $/b$/with "B" end, such as "AB" or "CB" ...
Sign
1, i/a/i is not case-sensitive, such as "a" or "a"
2. g/b/g Global match, find all matches
Method
1. var ret = "JavaScript". Search (/script/i) returns the position of the first match substring start character, no match returned-1
2. var ret = "JavaScript". Replace (/java/gi, "") to replace the second parameter of the function with a matched substring;
3. var ret = "JavaScript". Match (/(Java) (script)/gi) returns an array
Ret[0] Complete match "javascript"
RET[1] The first parenthesis matches the substring "Java"
RET[2] The second parenthesis matches the substring "script"
......
4. var ret = "JavaScript". Split (/a/) uses the parameter-matched substring as a separator to decompose the string to return an array
A summary of the basic knowledge of JavaScript's regular expressions