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-abc-expression/ below:

JavaScript RegExp [abc] Expression - GeeksforGeeks

JavaScript RegExp [abc] Expression

Last Updated : 11 Jul, 2025

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.

JavaScript
const regex = /[abc]/;
const str = "computer";

console.log(regex.test(str));
Syntax
/[abc]/ 
// or
new RegExp("[abc]")

Syntax with modifiers

/\[abc]/g 
// or
new RegExp("[abc]", "g")

Example 1: Searches the characters between [A-G] i.e uppercase A to uppercase G in the whole string. 

JavaScript
let str = 'GEEKSFORGEEKS: A computer science portal for geeks.';
let regex = /[A-G]/g;
let match = str.match(regex);

console.log(match);

Output
[
  'G', 'E', 'E',
  'F', 'G', 'E',
  'E', 'A'
]

Example 2: Searches the characters between [a-g] i.e lowercase a to lowercase in the whole string. 

JavaScript
let str = "GEEKSFORGEEKS: computer science portal for geeks.";
let regex = /[a-g]/g;
let match = str.match(regex);

console.log(match);

Output
[
  'c', 'e', 'c', 'e',
  'c', 'e', 'a', 'f',
  'g', 'e', 'e'
]
Supported Browsers

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.  



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