
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Match multiple occurrences in a string with JavaScript?
To match multiple occurrences in a string, use regular expressions. Following is the code −
Example
function checkMultipleOccurrences(sentence) { var matchExpression = /(JavaScript?[^\s]+)|(typescript?[^\s]+)/g; return sentence.match(matchExpression); } var sentence="This is my first JavaScript Program which is the subset of typescript"; console.log(sentence); console.log(checkMultipleOccurrences(sentence));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo70.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo70.js This is my first JavaScript Program which is the subset of typescript [ 'JavaScript', 'typescript' ]
- Related Questions & Answers
- Match all occurrences of a regex in Java
- Count number of occurrences for each char in a string with JavaScript?
- How to replace all occurrences of a string in JavaScript?
- Remove all occurrences of a multiple occurring element in an array in JavaScript
- Match multiple criteria inside an array with MongoDB?
- String replace multiple characters with an asterisk in JavaScript
- How to replace all occurrences of a string with another string in Python?
- Searching multiple columns for a row match in MySQL
- Count multiple occurrences of separate texts in MySQL?
- JavaScript match()
- How to match multiple criteria inside an array with MongoDB?
- Better ways to modify string with multiple methods using JavaScript
- How to count the number of occurrences of a character in a string in JavaScript?
- Python Program to Replace all Occurrences of ‘a’ with $ in a String
- Count occurrences of a character in string in Python
Advertisements