Skip to content
Justice Tech School

Regular Expressions in Practice

Regex patterns match text. Flags g, i and m change behaviour. Use test, match, matchAll and replace. Groups capture parts and named groups give names.

Example
const re = /(?<y>\d{4})-(?<m>\d{2})/;
const m = "Date: 2026-03".match(re);
console.log(m.groups.y, m.groups.m);
console.log(/^[\w.]+@[\w.]+\.\w+$/.test("ada@x.com"));
console.log("a1b22".replace(/\d+/g, "#"));

Exercise

Global flag.

/a/

Quiz Test

What does the i flag do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.