Open In App

JavaScript RegExp $ Quantifier

Last Updated : 10 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The RegExp m$ Quantifier in JavaScript is used to find the match of any string which contains m at the end of it

let str = "Geeksforh\nGeeks@_h";
let regex = /h$/gim;
let match = str.match(regex);

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

Syntax: 

/m$/ 

Example 1: Matches the presence of the word ‘123’ at the end of the string. 

let str = "Geeksfor123\nGeeks@_123";
let regex = /123$/gim;
let match = str.match(regex);

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

Output
Found 2 matches: 123,123

Example 2: This example replaces the word ‘K’ with ‘@’. 

let str = "@128GeeeeK";
let regex = new RegExp("K$", "gi");
let replace = "@";
let match = str.replace(regex, replace);
console.log(" New string: " + match);

Output
 New string: @128Geeee@

Recommended Links:


Next Article

Similar Reads

three90RightbarBannerImg