如何编写用于多个匹配的 JavaScript 正则表达式?
要查找多个匹配,请编写一个 JavaScript 正则表达式。你可以尝试运行以下代码,为多个匹配实现正则表达式 −
示例
<html>
<head>
<script>
var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three four',
a = document.createElement('a');
a.href = url;
var demoRegex = /(?:^|[&;])demo=([^&;]+)/g,
matches,
demo = [];
while (matches = demoRegex.exec(a.search)) {
demo.push(decodeURIComponent(matches[1]));
}
document.write(demo);
</script>
</head>
<body>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP