Home > Article > Web Front-end > How to use regular expressions to match multiple all data in js
What if we need to get all the content in the title?
Add g after the regular expression to indicate multiple matches
Method 1: match
Return array
Method 2
exec
The example is as follows:
<script> var str='<a href="//www.aliexpress.com/store/product/OOOT-BAORJCT-174296-22mm-10yard-lot-cartoon-Ribbons-Thermal-transfer-Printed-grosgrain-Wedding-Accessories-DIY-handmade/2349150_32810795709.html" rel="external nofollow" rel="external nofollow" title="OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons Thermal transfer Printed grosgrain Wedding Accessories DIY handmade material">OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons...</a><a href="//www.aliexpress.com/store/product/OOOT-BAORJCT-174296-22mm-10yard-lot-cartoon-Ribbons-Thermal-transfer-Printed-grosgrain-Wedding-Accessories-DIY-handmade/2349150_32810795709.html" rel="external nofollow" rel="external nofollow" title="999OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons Thermal transfer Printed grosgrain Wedding Accessories DIY handmade material">OOOT BAORJCT 174296 22mm 10yard/lot cartoon Ribbons...</a>'; var reg=/title="(.*?)">/g; var res = str.match(reg); console.log(str.match(reg)); while( res = reg.exec(str)) { console.log(res[1]); } </script>
The effect is as follows:
Recommended related tutorials: js tutorial
The above is the detailed content of How to use regular expressions to match multiple all data in js. For more information, please follow other related articles on the PHP Chinese website!