Open In App

JavaScript RegExp * Quantifier

Last Updated : 29 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax: 

/m*/ 

or

new RegExp("m*")

Syntax with modifiers:

/\m*/g 

or

new RegExp("m*", "g")

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

Javascript




function geek() {
    let str1 = "GeeksforGeeks@_123_G$";
    let regex4 = /Ge*/gi;
    let match4 = str1.match(regex4);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek();


Output

Found 3 matches: Gee,Gee,G

Example 2: This example replaces the occurrence of 128* with the word “Geeky”. 

Javascript




function geek() {
    let str1 = "GEEK@128";
    let regex4 = new RegExp("128*", "gi");
    let replace = "Geeky";
    let match4 = str1.replace(regex4, replace);
 
    console.log(" New string: " + match4);
}
geek();


Output

 New string: GEEK@Geeky

Supported Browsers: The browsers supported by RegExp * Quantifier are listed below:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer

We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Complete Reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.  


Previous Article
Next Article

Similar Reads

JavaScript RegExp ? Quantifier
The m? Quantifier in JavaScript is used to find the match of any string that contains zero or one occurrence of m. Syntax: /m?/ or new RegExp("m?") Syntax with modifiers: /\m?/g or new RegExp("m?", "g") Example 1: This example matches the word e followed by zero or one occurrence of k. C/C++ Code function geek() { let str1 = "GeeksforGeeks@_12
1 min read
JavaScript RegExp + Quantifier
The m+ Quantifier in JavaScript is used to find the match of any string that contains at least one m. Syntax: /m+/ or new RegExp("m+") Syntax with modifiers: /\m+/g or new RegExp("m+", "g") Example 1: This example matches the presence of the word 'e' in the whole string. C/C++ Code function geek() { let str1 = "GeeksforGeeks@_123_$"; let
1 min read
JavaScript RegExp {X} Quantifier
The RegExp m{X} Quantifier in JavaScript is used to find the match of any string that contains a sequence of m, X times where X is a number. Syntax: /m{X}/ or new RegExp("m{X}") Syntax with modifiers: /\m{X}/g or new RegExp("m{X}", "g") Example 1: This example matches the presence of the word 'ee' in the whole string. C/C++ Code function geek() { l
2 min read
JavaScript RegExp ?! Quantifier
The RegExp ?!m Quantifier in JavaScript is used to find the match of any string which is not followed by a specific string m. Syntax: /?!m/ or new RegExp("?!m") Syntax with modifiers: /\?!m/g or new RegExp("?!m", "g") Example 1: This example matches the words 'Geeks' not followed by 123 in the whole string. C/C++ Code function geek() { let str1 =
2 min read
JavaScript RegExp ^ Quantifier
The RegExp ^m Quantifier in JavaScript is used to find the match of any string which contains m at the beginning of it. Syntax: /^m/ or new RegExp("^m") Syntax with modifiers: /\^m/g or new RegExp("^m", "g") Example 1: This example matches the presence of word 'Geeks' at the beginning of the string. C/C++ Code function geek() { let str1 = "Gee
1 min read
JavaScript RegExp $ Quantifier
The RegExp m$ Quantifier in JavaScript is used to find the match of any string which contains m at the end of it. Syntax: /m$/ or new RegExp("m$") Syntax with modifiers: /\m$/g or new RegExp("m$", "g") Example 1: This example matches the presence of the word '123' at the end of the string. C/C++ Code function geek() { let str1 = "Geeksfor123\n
1 min read
JavaScript RegExp {X,Y} Quantifier
JavaScript RegExp {X,Y} QuantifierThe RegExp m{X, Y} Quantifier in JavaScript is used to find the match of any string that contains a sequence of m, X to Y times where X, Y must be numbered. Syntax: /m{X, Y}/ or new RegExp("m{X, Y}") Syntax with modifiers: /\m{X, Y}/g or new RegExp("m{X}", "g") Example 1: This example matches the presence of the wo
2 min read
JavaScript RegExp {X,} Quantifier
The RegExp m{X, } Quantifier in JavaScript is used to find the match of any string that contains a sequence of m, at least X times, where X is a number. Syntax: /m{X, }/ or new RegExp("m{X, }") Syntax with modifiers: /\m{X, }/g or new RegExp("m{X, }", "g") Example 1: This example matches the presence of the character 'e' at least 1 times in the who
2 min read
JavaScript RegExp toString() Method
The RegExp toString() Method in JavaScript is used to return the string value of the regular expression. Syntax: RegExpObject.toString() Example 1: This example returns the string value of the regular expression. C/C++ Code function geek() { let regex = new RegExp("[a-c]", "gi"); let rex = regex.toString(); console.log(rex); } g
1 min read
JavaScript RegExp (x|y) Expression
The RegExp (x|y) Expression in JavaScript is used to search any of the specified characters (separated by |). Syntax: /(x|y)/ or new RegExp("(x|y)") Syntax with modifiers: /(x|y)/g or new RegExp("(x|y)", "g") Example 1: This example searches the word "GEEKS" or "portal" in the whole string. C/C++ Code function geek() { let str1 = "GEEKSFORGEEK
2 min read