5 min read
2026-02-05
Don't try to write the perfect expression right away. Add conditions gradually, testing each step.
(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})Named groups make code self-documenting.
Greedy `.*` may grab more text than needed. Use lazy `.*?` for minimal matching.
A period, an asterisk, parentheses - they all have special meaning. For a literal match, add `\\`.
Empty line
String of one character
Very long line
Unicode characters
`^` — beginning of the line
`$` — end of line
`\\b` - word boundary
In `x` (verbose) mode you can add comments inside the regex.
See also: JS Beautifier, Diff Checker, JSON Formatter