Lesson content
Read, practise, then check your understanding
Regular expressions are concise pattern programs. Literals suit fixed patterns; new RegExp supports runtime construction and requires careful escaping.
Structured matching
const pattern = /^(?<user>[a-z0-9._-]+)@(?<host>[a-z0-9.-]+)$/iu;
const match = pattern.exec(input);
if (match) console.log(match.groups.user, match.groups.host);
Classes, quantifiers, groups, alternation, anchors, and lookarounds express constraints. Flags include global, case-insensitive, multiline, dotAll, Unicode, and sticky behavior. A global regex mutates lastIndex. Escape user-supplied fragments and avoid nested ambiguous quantifiers that enable catastrophic backtracking. Use a parser for complex grammars.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.