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-quantifier-4/ below:

JavaScript RegExp ?! Quantifier - GeeksforGeeks

JavaScript RegExp ?! Quantifier

Last Updated : 11 Jul, 2025

The RegExp ?!m Quantifier in JavaScript is used to find the match of any string which is not followed by a specific string m

JavaScript
// 3-digits not followed by any numbers
const str = "123Geeks12345@";
const regex = /\d{3}(?!\d)/g;

const match = str.match(regex);
console.log(match); 
Syntax
/?!m/ 

Example 1: Matching the words 'Geeks' not followed by 123 in the whole string. 

JavaScript
let str = "Geeks for 123 Geeks@";
let regex = /Geeks(?!123)/g;
let match = str.match(regex);

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

Output
Found 2 matches: Geeks,Geeks

Example 2: Replacing the word '128' with '#' symbol.

JavaScript
let str = "@128Geek128";
let regex = new RegExp("128(?!ee)", "gi");
let replace = "#";
let match = str.replace(regex, replace);
console.log("New string: " + match);

Output
New string: @#Geek#
Recommended Links:

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