A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-regexp-xy-quantifier/ below:

JavaScript RegExp {X,Y} Quantifier - GeeksforGeeks

JavaScript RegExp {X,Y} Quantifier

Last Updated : 11 Jul, 2025

JavaScript RegExp {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. 

JavaScript
// Matches between 2 and 4 digits
const regex = /\d{2,4}/;
console.log(regex.test("123"));
console.log(regex.test("12345"));
console.log(regex.test("12"));
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: Matching the presence of the word between [a-g] of length 3 to 4 in the whole string. 

JavaScript
let str = "GeeksforGeeeeks@_123_$";
let regex = /[a-g]{3,4}/gi;
let match = str.match(regex);

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

Output
Found 2 matches: Gee,Geee

Example 2: This example replaces the word 'ee' or 'eee' with '$'. 

JavaScript
let str = "ee@128GeeeeK";
let regex = new RegExp("e{2,3}", "gi");
let replace = "$";
let match = str.replace(regex, replace);
console.log(" New string: " + match);

Output
 New string: $@128G$eK
Supported Browsers

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.  



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4