Computer Science & Data / Programming

Regex Tester

//g

$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

Pattern(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Flagsg
TextInvoice 2026-03-14 was paid on 2026-04-02; the next one is due 2026-05-01.
Result
Matches3
First match2026-03-14 at index 8: year 2026, month 03, day 14

\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.