Glossary
Regular Expression (Regex)
A sequence of characters that defines a pattern for matching, extracting, or replacing text. Regular expressions use character classes ([a-z], \d, \w), quantifiers (*, +, {n}), anchors (^, $, \b), groups ((), (?:)), and alternation (|) to describe text patterns.
A regular expression (regex) is a formal language for describing text patterns. It uses metacharacters alongside literal characters to specify matching rules: character classes like \d for digits, quantifiers like + for one or more, anchors like ^ for start of string, and groups like (abc) for capturing substrings. Every major programming language includes a regex engine.
Basic Syntax
. Any character except newline
\d Digit [0-9]
\w Word character [a-zA-Z0-9_]
\s Whitespace
^ Start of string (or line in multiline mode)
$ End of string
* Zero or more (greedy)
+ One or more (greedy)
? Zero or one
{n} Exactly n times
{n,m} Between n and m times
[abc] Character class — matches a, b, or c
[^a] Negated class — anything except a
(abc) Capturing group
| Alternation (OR)
\b Word boundary
Named Groups
const match = "2026-06-15".match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/);
match.groups.year // "2026"
match.groups.month // "06"
match.groups.day // "15"
Lookahead and Lookbehind
foo(?=bar) # "foo" only if followed by "bar"
foo(?!bar) # "foo" only if NOT followed by "bar"
(?<=\$)\d+ # digits preceded by $
(?<!\$)\d+ # digits NOT preceded by $
Common Patterns
Email: ^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$
URL: https?:\/\/[\w\-.]+\.[a-zA-Z]{2,}(\/[\w\-./?%&=]*)?
Date: ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
HEX: ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
IPv4: ^(\d{1,3}\.){3}\d{1,3}$
Flags
/pattern/i Case-insensitive
/pattern/g Global (find all matches)
/pattern/m Multiline (^ and $ match line boundaries)
/pattern/s Dotall (. matches newlines)
/pattern/u Unicode mode
Test and debug patterns with the Regex Tester Tool.