JavaScript Regular Expressions —
Covers: syntax, flags, character classes, quantifiers, groups, assertions, Unicode, APIs, performance, pitfalls, debugging, common patterns, and interview questions.
1. Basics — what a RegExp is
A RegExp is a pattern describing a set of strings. Two creation forms:
const r1 = /abc/i; // literal form, flags after closing slash
const r2 = new RegExp("a\d+", "g"); // constructor form; note double-escaping in string
/…/ is parsed at script-compile time; RegExp() builds at runtime.
2. Flags (modifiers)
g— global: find all matches; affectslastIndexforexec()andtest()behavior.i— ignore case.m— multiline:^and$match at line boundaries.s— dotAll:.matches newline.u— unicode: enables full Unicode semantics (code points,