Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptJavaScript RegExp Expression

JavaScript RegExp [^abc] Expression

The RegExp [^abc] Expression in JavaScript is used to search for any character which is not between the brackets. The character inside the brackets can be a single character or a span of characters.

  • [A-Z]: It is used to match any character from uppercase A to uppercase Z.
  • [a-z]: It is used to match any character from lowercase a to lowercase z.
  • [A-z]: It is used to match any character from uppercase A to lowercase z.
  • [abc…]: It is used to match any character between the brackets.

Syntax: 

/[^abc]/ 

or

new RegExp("[^abc]")

Syntax with modifiers:

/\[^abc]/g 

or

new RegExp("[^abc]", "g")

Example 1: This example searches the characters which are not present between [A-G] i.e uppercase A to uppercase G in the whole string. 

Javascript




function geek() {
    let str1 = "GEEKSFORGEEKS is the computer "
        + "science portal for neveropen.";
 
    let regex4 = /[^A-Z]/g;
    let match4 = str1.match(regex4);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek()


Output

Found 42 matches:  ,i,s, ,t,h,e, ,c,o,m,p,u,t,e,r, ,s,c,i,e,n,c,e, ,p,o,r,t,a,l, ,f,o,r, ,g,e,e,k,s,.

Example 2: This example searches the characters which are not present between [a-g] i.e lowercase a to lowercase g in the whole string. 

Javascript




function geek() {
    let str1 = "GEEKSFORGEEKS is the computer "
        + "science portal for neveropen.";
 
    let regex4 = /[^a-p]/g;
    let match4 = str1.match(regex4);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek()


Output

Found 31 matches: G,E,E,K,S,F,O,R,G,E,E,K,S, ,s, ,t, ,u,t,r, ,s, ,r,t, ,r, ,s,.

Supported Browsers: The browsers supported by RegExp [^abc] 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