หากต้องการค้นหาหลายรายการที่ตรงกัน ให้เขียนนิพจน์ทั่วไปของ 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>