How to useJavaScript String match() Method in Javascript
The JavaScript String match() method is an inbuilt function in JavaScript used to search a string for a match against any regular expression. If the match is found, then this will return the match as an array.
Syntax:
string.match( regExp );
Example: This example illustrates matching a single character with Multiple possibilities using the String match() Method
// Create input string
let string = "w3wiki";
// Create global regular expression
// containing letters to be matched
let regx = /[aeiou]/g;
// Store results from string match method
let result = [...string.match(regx)];
// Display the result
console.log(result);
Output
[ 'e', 'e', 'o', 'e', 'e' ]
JavaScript Program to Match Single Character with Multiple Possibilities
In this article, we will write programs to check all possible matching in JavaScript. We will check the occurrence of characters individually in the given string or sequence. In this article, we will check the occurrence of vowels in the given string.
Table of Content
- Using JavaScript RegExp test() Method
- Using JavaScript String match() Method
- Using JavaScript String includes() Method
- Using JavaScript String indexOf() Method
- Using Array.some()