Get online today — Domain + Hosting at discounted prices View Combo Offers ›

Regex Tester

Test a PCRE pattern against your text and see every match and group.

Test a regular expression against sample text and see every match, every capture group and where each one starts. Switch to replace mode to preview the result of a substitution before you run it against real data.

The engine is PCRE — the same one PHP, Apache mod_rewrite and nginx use — so what works here works in an .htaccess file.

How it works

Write the pattern without delimiters; the flags are separate checkboxes below. Four flags cover nearly everything. i makes matching case-insensitive. m (multiline) makes ^ and $ match at every line break instead of only at the very start and end of the subject. s (dotall) lets . match a newline, which it otherwise never does. u switches the engine to UTF-8 mode so that accented characters and emoji count as single characters rather than individual bytes — essential for any non-ASCII input.

Parentheses do two jobs. (…) both groups and captures, and each capture is numbered left to right by its opening bracket. (?:…) groups without capturing, which is what you want when the parentheses exist only to apply a quantifier. (?<name>…) captures under a name, which is worth the extra characters the moment a pattern has more than two groups.

The main trap is greediness. .* takes as much as it can and then gives characters back until the rest of the pattern fits, so <.*> against <a><b> matches the whole string rather than just <a>. Adding ? makes a quantifier lazy — <.*?> stops at the first >. Better still, match the negated class: <[^>]*> cannot overshoot at all and runs faster.

That performance point deserves its own warning. Nested quantifiers over overlapping alternatives — the classic (a+)+$ — can drive the engine into exponential backtracking, where a slightly longer input takes catastrophically longer to fail. This is a real denial-of-service vector in production code. Patterns run here have a deliberately low backtrack limit, so a pattern of that shape reports a failure rather than hanging; treat that failure as a finding about the pattern, not a limitation of the tool.

Frequently asked questions

Do I include the slashes around my pattern?

No. Enter the pattern only, without delimiters, and tick the flags you want below. If you paste something like /^abc$/i the slashes are treated as literal characters to match, which is almost certainly not what you meant.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers such as * and + consume as much as possible and then backtrack until the rest of the pattern fits. Adding ? makes them lazy, so they consume as little as possible. Where you can, matching a negated character class instead is both clearer and faster.

Why does my pattern fail on accented characters?

Without the u flag, PCRE works on bytes, so a multi-byte UTF-8 character is several separate units and a dot matches only the first of them. Tick the Unicode flag; then \w, \b and character classes behave per character.

What does "backtrack limit exhausted" mean?

The pattern forced the engine into more backtracking than allowed. It nearly always signals catastrophic backtracking from nested quantifiers such as (a+)+. Rewrite the pattern to remove the ambiguity — the same shape would be a denial-of-service risk in production.

Can I use this for .htaccess rewrite rules?

Yes. Apache mod_rewrite uses PCRE, so a pattern that behaves here behaves there. Remember that RewriteRule matches the path with no leading slash, and that per-directory rules have the directory prefix stripped before matching.

Should I use a regex to parse HTML?

No. HTML nests arbitrarily and regular expressions cannot express that, so any pattern will break on the first unusual document. Use a parser — DOMDocument in PHP. Regex is fine for a narrow, well-known fragment, but not for general markup.

Related tools

Need hosting that just works?

Free SSL, daily backups and 24×7 support on every Loudhost plan.

View Hosting Plans