What Regular Expressions Actually Are
A regular expression is a compact pattern language that describes a set of strings. The regex /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i describes “any string that looks like an email address.” Test and debug yours with our live Regex Tester.
The Six Concepts That Cover 80% of Real-World Regex
- Character classes
[abc]: Match any one character in the set.[0-9]matches any digit. - Quantifiers
*, +, ?, {n}: Zero or more, one or more, zero or one, exactly n. - Anchors
^ $:^matches the start;$matches the end. Without anchors, patterns can match anywhere inside a string. - Groups
(abc): Treat multiple characters as a single unit.(ab)+matches “ab”, “abab”, “ababab”. - Alternation
a|b: Match either the left or right pattern.cat|dogmatches either word. - Escape sequences
\d \w \s:\d=[0-9],\w= word characters,\s= any whitespace.
Catastrophic Backtracking: Why Some Regex Patterns Hang Servers
Nested quantifiers like (a+)+ applied to a long non-matching string can cause exponential backtracking. This is called ReDoS (Regular Expression Denial of Service) and has taken down production servers. Always test patterns against adversarial non-matching input, not just matching examples.