JavaScript | RegExp [abc] Expression
The RegExp [abc] Expression in JavaScript is used to search any character 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 Z.
- [a-z]: It is used to match any character from lowercase a to 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 between [A-G] i.e uppercase A to uppercase G in the whole string.
<!DOCTYPE html> <html> <head> <title> JavaScript RegExp [abc] Expression </title> </head> <body style="text-align:center"> <h1 style="color:green"> GeeksforGeeks </h1> <h2>RegExp [abc] Expression</h2> <p> GEEKSFORGEEKS is the computer science portal for geeks. </p> <button onclick="geek()"> Click it! </button> <p id="app"></p> <script> function geek() { var str1 = "GEEKSFORGEEKS is the computer" + " science portal for geeks."; var regex4 = /[A-G]/g; var match4 = str1.match(regex4); document.getElementById("app").innerHTML = "Found " + match4.length + " matches: " + match4; } </script> </body> </html> |
Output:
- Before Clicking the button:

- After Clicking the button:

Example 2: This example searches the characters between [a-g] i.e lowercase a to lowercase g in the whole string.
<!DOCTYPE html> <html> <head> <title> JavaScript RegExp [abc] Expression </title> </head> <body style="text-align:center"> <h1 style="color:green"> GeeksforGeeks </h1> <h2>RegExp [abc] Expression</h2> <p> GEEKSFORGEEKS is the computer science portal for geeks. </p> <button onclick="geek()"> Click it! </button> <p id="app"></p> <script> function geek() { var str1 = "GEEKSFORGEEKS is the computer" + " science portal for geeks."; var regex4 = /[a-g]/g; var match4 = str1.match(regex4); document.getElementById("app").innerHTML = "Found " + match4.length + " matches: " + match4; } </script> </body> </html> |
Output:
- Before Clicking the button:

- After Clicking the button:

Supported Browsers: The browsers supported by RegExp [abc] Expression are listed below:
- Google Chrome
- Apple Safari
- Mozilla Firefox
- Opera
- Internet Explorer
Recommended Posts:
- JavaScript | RegExp [^abc] Expression
- JavaScript | RegExp [0-9] Expression
- JavaScript | RegExp [^0-9] Expression
- JavaScript | RegExp (x|y) Expression
- JavaScript | RegExp * Quantifier
- JavaScript | RegExp \D Metacharacter
- JavaScript | RegExp ? Quantifier
- JavaScript | RegExp + Quantifier
- JavaScript | RegExp \t Metacharacter
- JavaScript | RegExp \v Metacharacter
- JavaScript | RegExp \xxx Metacharacter
- JavaScript | RegExp \xdd Metacharacter
- JavaScript | RegExp {X,} Quantifier
- JavaScript | RegExp constructor
- JavaScript | RegExp {X} Quantifier
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



