Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write JavaScript Regular Expression for multiple matches?
To find multiple matches, write a JavaScript regular expression. You can try to run the following code to implement regular expression for multiple matches −
Example
<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>Advertisements