Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptJavaScript RegExp Expression

JavaScript RegExp [^0-9] Expression

The RegExp [^0-9] Expression in JavaScript is used to search any digit which is not between the brackets. The character inside the brackets can be a single digit or a span of digits. 

Syntax: 

/[^0-9]/ 

or

new RegExp("[^0-9]")

Syntax with modifiers:

/[^0-9]/g 

or

new RegExp("[^0-9]", "g")

Example 1: This example searches the digits which are not present between [0-4] in the whole string. 

Javascript




function geek() {
    let str1 = "123456790";
    let regex4 = /[^0-4]/g;
    let match4 = str1.match(regex4);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek();


Output

Found 4 matches: 5,6,7,9

 Example 2: This example searches the digits which are not present between [0-9] in the whole string and replaces the characters with hash(#). 

Javascript




function geek() {
    let str1 = "128@$%";
    let replacement = "#";
    let regex4 = new RegExp("[^0-9]", "g");
    let match4 = str1.replace(regex4, replacement);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek();


Output

Found 6 matches: 128###

 Supported Browsers: The browsers supported by RegExp [^0-9] Expression 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.  

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments