🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #85

JS RegExp Classes

Character Classes are characters enclosed in square brackets [].

A character class matches any character from a set within brackets:

// Match Digits

const pattern = /[0-9]/;

JavaScript Regex Character Classes

Revised July 2025

Col 1 Col 2
Class Description
[a] Matches the character between the brackets
[^a] Matches all characters NOT between the brackets
[abc] Matches all characters between the brackets
[^abc] Matches all characters NOT between the brackets
[a-z] Matches all characters in the range from a to z
[^a-z] Matches all characters NOT in the range from a to z
[0-9] Matches all characters in the range from 0 to 9
[^0-9] Matches all characters NOT in the range from 0 to 9

Example [HW]

let text = "Hello World!";

const pattern = /[HW]/g;

let result = text.match(pattern);

Example [A-Z]

let text = "This is W3School";

const pattern = /[A-Z]/g;

let result = text.match(pattern);

Example [1234]

let text = "123456789";

const pattern = /[1234]/g;

let result = text.match(pattern);

Example [1-4]

let text = "123456789";

const pattern = /[1-4]/g;

let result = text.match(pattern);

Note: [01234] is the same as [0-4] [abcde] is the same as [a-e]


Regular Expression Methods

Regular Expression Search and Replace can be done with different methods.

These are the most common:

String Methods

Col 1 Col 2
Method Description
match(regex) Returns an Array of results
matchAll(regex) Returns an Iterator of results
replace(regex) Returns a new String
replaceAll(regex) Returns a new String
search(regex) Returns the index of the first match
split(regex) Returns an Array of results

RegExp Methods

Col 1 Col 2
Method Description
regex.exec() Returns an Iterator of results
regex.test() Returns true or false

Note: See Also: JavaScript RegExp Tutorial JavaScript RegExp Flags JavaScript RegExp Meta Characters JavaScript RegExp Assertions JavaScript RegExp Groups JavaScript RegExp Quantifiers JavaScript RegExp Patterns JavaScript RegExp Objects JavaScript RegExp Methods

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS RegExp Classes – FAQs

Quick answers about learning JS RegExp Classes in JavaScript.

This free note from CodingNow 2.0 explains JS RegExp Classes in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including JS RegExp Classes, is 100% free with no signup required.
With focused practice, most students grasp JS RegExp Classes in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now