Regex Tester
$1, $2 for numbered groups, $<name> for named groups, $& for the whole match
Try an example
Matching…
Test a regular expression against your text and see every match highlighted, with its position and capture groups (numbered and named), and preview a find-and-replace. It uses your browser's JavaScript regex engine, with the g, i, m, s, u and y flags.
Formula
\d digit, \w word character, \s whitespace, . any character
* zero or more, + one or more, ? optional, {n,m} between n and m times
(…) group, (?<name>…) named group, a|b either, ^ start, $ end
Worked Example
\d{4} matches exactly four digits and each named group (?<name>…) captures part of the date. Without the g flag only the first date would be found.
Frequently Asked Questions
What do the regex flags g, i, m and s do?
g finds every match instead of only the first; i ignores case; m makes ^ and $ match at the start and end of each line rather than of the whole text; s lets . match line breaks too. u enables full Unicode matching, and y (sticky) only matches at the current position.
Why does my pattern match too much?
Quantifiers such as .* are greedy and take as much text as they can, so <.*> matches from the first < to the last > on the line. Add ? to make them lazy (<.*?>), or use a negated class such as <[^>]*>.
Will a regex that works here work in Python or Java?
Most syntax is shared, but details differ: Python writes named groups as (?P<name>…), lookbehind support varies, and flags are set differently. Test in the target language before relying on edge cases.