Open In App

JavaScript RegExp * Quantifier

Last Updated : 10 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The RegExp m* Quantifier in JavaScript is used to find the match of any string that contains zero or more occurrences of match

JavaScript
let str = "GeeksforGeeks@_123_G$";
let regex = /ke*/gi;
let match = str.match(regex);

console.log("Found " + match.length
    + " matches: " + match);

Output
Found 2 matches: k,k

Syntax: 

/m*/ 

Example 1: Matches the zero or more occurrences of the word ‘e’ in the whole string. 

JavaScript
let str = "GeeksforGeeks@_123_G$";
let regex = /Ge*/gi;
let match = str.match(regex);

console.log("Found " + match.length
    + " matches: " + match);

Output
Found 3 matches: Gee,Gee,G

Example 2: Replaces the occurrence of 128* with the word “Geeky”. 

JavaScript
let str = "GEEK@128";
let regex = new RegExp("128*", "gi");
let replace = "Geeky";
console.log(str.replace(regex, replace));

Output
GEEK@Geeky

Recommended Links:


Next Article

Similar Reads