Skip to content

Regex Tester & Generator

Free · Data & Config · runs in your browser

By Nayeem, Software Developer of fastsavemedia.comLast reviewed
Regex cheat sheet: the tokens you will use most
TokenMeaningExample match
\d \w \sDigit, word character, whitespace\d{4} matches 2026
. * + ?Any char; zero-or-more; one-or-more; optionalcolou?r matches color and colour
[abc] [^abc]Character set; negated set[0-9a-f] matches a hex digit
^ $ \bStart, end, word boundary^\w+ matches the first word
( ) (?: )Capture group; non-capturing group(\d+)-(\d+) captures both parts
{n} {n,} {n,m}Exact, at least, between n and m repeats\w{8,} matches 8+ word chars
(?= ) (?! )Positive and negative lookahead\d+(?= px) matches digits before px
(?<name> )Named capture group(?<year>\d{4}) exposes groups.year
$1 $& $<name>Replacement: group 1, whole match, named group(\w+)@ with [$1] turns ann@ into [ann]
g i m s u yFlags: all matches, ignore case, per-line ^ $, dot matches newline, Unicode, stickyWithout g, only the first match is found

Key Takeaways

Anchor when you can

Use ^ and $ for full-string validation, to restrict matches; performance depends on the pattern and input.

Avoid nested quantifiers

Patterns like (a+)+ can backtrack catastrophically, rewrite them where semantics permit. JavaScript does not support possessive quantifiers.

Prefer named groups

(?<year>\d{4}) is self-documenting and survives reordering better than numeric groups.

Use character classes

\d, \w, \s are shorter than [0-9], [A-Za-z0-9_], [ \t\n].

Lookarounds are powerful

Zero-width assertions (?=...) and (?<=...) let you match without consuming.

Test with edge cases

Empty strings, Unicode, leading whitespace, newlines, the test data generator above seeds these for you.

Common Use Cases

Form validation

Email, phone, ZIP, password strength, client and server-side.

Log parsing

Extract timestamps, IPs, status codes from access logs.

Secret scanning

Detect JWTs, API keys and credentials in source code.

Code refactoring

Find candidates for simple replacements; use a syntax-aware refactoring tool for structural code changes.

ETL & data cleaning

Normalize phone numbers, currencies, dates and identifiers.

Security rules

WAF rules, input sanitization, deny-list patterns.

Troubleshooting

My pattern matches nothing, what's wrong?

Check your anchors. ^ and $ require the entire string (or line in multiline mode) to match. Remove them, or enable the m flag to match per line.

Why does . not match newlines?

By default, . matches any character except newline. Enable the s (dotall) flag, or use [\s\S].

My regex hangs the browser.

You likely hit catastrophic backtracking, open the Complexity tab. Replace nested quantifiers like (a+)+ with a+, or use atomic groups in PCRE-flavored engines.

Group 1 is empty but the match isn't.

You used a non-capturing group (?:...). Switch to (...) to capture, or name it with (?<name>...).

Unicode characters don't match \w.

\w only covers ASCII [A-Za-z0-9_]. Use the u flag and Unicode property escapes like \p{L}.

How to use regex find and replace

Type a replacement in Replace with and the replaced text appears under the matches, with a count and matching code for JavaScript, Python, Java and Go. In the replacement, $1 inserts group 1, $& inserts the whole match, $<name> inserts a named group and $$ inserts a literal dollar sign. Turn off the g flag to replace only the first match.

Each language spells these differently. Python uses \g<1> or \g<name>, and Java, C# and Go use ${name} for named groups. The generated snippets already convert the syntax for you.

Why your regex works here but not in another language

FeatureJavaScriptPython reJavaGo / Rust
Lookahead (?=…)YesYesYesNo
Lookbehind (?<=…)Yes, any lengthFixed length onlyBounded lengthNo
Backreference \1YesYesYesNo
Named group(?<n>…)(?P<n>…)(?<n>…)(?P<n>…) (newer versions also accept (?<n>…))
Possessive a++NoYes (3.11+)YesNo
Catastrophic backtrackingPossiblePossiblePossibleNot possible (linear time)

Go and Rust use engines that guarantee linear-time matching, which is why they reject lookaround and backreferences. If a pattern needs those, rewrite it or do a second pass in code.

Stop a regex from freezing your app

A pattern such as (a+)+$ can try an exponential number of paths when the text almost matches. This tester runs each new pattern in a separate worker and stops it after 1.5 seconds, so the page stays usable. To fix the pattern itself, remove nested quantifiers ((a+)+ becomes a+), make alternatives mutually exclusive ((a|a)* is a red flag), and anchor with ^ and $ when validating whole values.

Frequently asked questions

What is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern, used for matching, finding and replacing strings of text.

How do I test a regex online?

Paste your pattern into the Pattern field and your test string into the Test Input field. Regex Studio matches live as you type and highlights all matches, groups and named groups.

How do I find and replace with regex?

Enter your pattern and text, then type a replacement such as [$1] in the Replace with field. Use $1 for a numbered group, $& for the whole match and $<name> for a named group. The g flag replaces every match; without it only the first is replaced.

Why does my regex only find one match?

The g (global) flag is off. Without it, a JavaScript regex stops at the first match. Turn g on to find every match in the text.

What is catastrophic backtracking?

Catastrophic backtracking happens when a regex engine tries exponentially many ways to match a string due to nested quantifiers like (a+)+. It can freeze applications. Regex Studio detects risky patterns and suggests safer alternatives.

Which regex flavor is supported?

The live tester uses the JavaScript (ECMAScript) regex engine, which is close to PCRE. The Language Generator emits idiomatic code for Java, JavaScript, Python, C#, PHP, Go, Rust, Kotlin and Ruby.

Is Regex Studio free?

Yes. Regex Studio is 100% free, requires no signup, and runs entirely in your browser. Your patterns and test data never leave your device.