1 <script type="text/javascript"> 2 var str = "ABCDE"; 3 var reg = /(A+)((B|C|D)+)(E+)/gi; 4 console.log(str.match(reg));//输出:["ABCDE"] 5 console.log(reg.exec(str,‘i‘));//输出:["ABCDE", "A", "BCD", "D", "E"] 6 console.log(RegExp.$1);//输出:"A" 7 console.log(RegExp.$2);//输出:"BCD" 8 console.log(RegExp.$3);//输出:"D" 9 console.log(RegExp.$4);//输出:"E 10 </script>
https://www.cnblogs.com/caoruiy/p/4413370.html