The example in this article describes how JavaScript uses regular expressions to obtain all grouped contents. Share it with everyone for your reference, the details are as follows:
1. Need to use regular expression exec
2. Need to loop
DEMO example: (The following code will output 8 , 9. Two matched group contents)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JS正则demo</title> </head> <body> <script> var r = /\{ab(\d)ab}/g; while ((resultS2 = r.exec("ab{ab8ab}c{ab9ab}")) != null) { console.log(resultS2[1]); } </script> </body> </html>
The running effect diagram is as follows:
I hope this article will be helpful to everyone’s JavaScript programming. .
For more examples of how JavaScript uses regular expressions to obtain all grouped content, please pay attention to the PHP Chinese website for related articles!