bhylu.com

Advertisements

JS RegExp Objects

The RegExp constructor builds a pattern from a string. String escaping and pattern escaping are separate steps.

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

const digits = new RegExp("^\\d{3}$");
console.log(digits.test("204"));

What happens

The three-digit string matches.