Limit the scope of the quantifiers. The range of the multiple choice structure is reverse reference. Capture text groups. capture only groups. do not capture foresight. 1. define the range of quantifiers. var reg1 =/(Matz )? // 0 or one Matzvar reg2 =/(Matz) +/; // Matzvar reg3 =/(Matz )*/; // 0 or multiple Matz 2. Specify the range of multiple-choice structures var reg =/(Matz | Eich)/reg. test ('matz') // => truereg. test ('eich ') // => truereg. test ('john') // => false 3. Capture the text var reg =/(boy) \ 1 // equivalent to/boyboy/reg for reverse reference. test ('boys') // => falsereg. test ('boyboy ') // => true var reg/(boy) (girl) \ 1 \ 2/reg. test ('boygirlboygir') // => true 4. Group capture var reg1 =/(\ d {3}) (\ d {3 })/ Var str = '2014 111 'str. replace (reg1, '$2 $ 1') // => '2017 111111'. Pay attention to the $2, $1, stores the matched string var reg2 =/(\ d {3}) (\ d {4}) (\ d {4})/var mobile = '000000' reg2. test (mobile) RegExp. $1 // => 135RegExp. $2 // => 2272RegExp. $3 // => 2724 var reg3 =/(\ d {3}) (\ d {4}) (\ d {4 }) /var mobile = '000000' mobile. replace (reg3, '$1 $2 $ 3') // => '2017 135 2272 1111' 5. Only groups do not capture (and "?: "Together) var reg = /(?: \ D +)/reg. test ('20140901') RegExp. $1 // => ''in a regular expression that does not store long matching elements, reverse referencing reduces the matching speed and performance. grouping is not captured when reverse referencing is not required. 6. lookahead and "? = ") It tells the regular expression to look forward to some characters but not move the position. Forward does not match any character and only matches the specific position in the text. Var reg =/(John )(? = Resig)/reg. test ('john') // => falsereg. test ('John backus') // => falsereg. test ('John reisg') // => trueRegExp. $1 // => 'john'. Note that this is not "John Resig"