Home > Web Front-end > JS Tutorial > body text

Example of how JavaScript uses regular expressions to obtain all grouped contents

高洛峰
Release: 2017-01-20 14:00:11
Original
1336 people have browsed it

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>
Copy after login

The running effect diagram is as follows:

Example of how JavaScript uses regular expressions to obtain all grouped contents

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template