bhylu.com

Advertisements

JS RegExp Classes

Character classes describe which characters may occur at one position. A range such as A-Z matches one uppercase ASCII letter.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

console.log("AB-42".match(/[A-Z]/g));
console.log("AB-42".match(/\d/g));

What happens

The separate matches are A and B, then 4 and 2.