Regex Tester
Test regular expressions live: matches, capture groups and replace, with a library of 15 ready-made patterns.
Regex Tester - Test Regular Expressions Online with Live Matches
Writing a regular expression is guesswork until you can see what it matches. This free regex tester runs your pattern against your own sample text as you type and highlights every match, so you find the mistake in seconds instead of pushing a broken validation rule to production.
Type the pattern in one field, the flags in the next, and paste the text you want to test underneath. The matches update immediately, and an invalid pattern is reported straight away rather than failing silently.
What a regex tester is really for
Most regex bugs are not exotic. A pattern matches too much, matches too little, or works on the one example you had in mind and fails on the second. A tester turns that invisible behaviour into something you can look at: paste five realistic inputs, including the awkward ones, and watch which of them light up. It is also the fastest way to learn the syntax, because you can change one character and immediately see the consequence.
How to use this regex tester
- Enter your pattern without the surrounding slashes - for example
[a-z]+\d{2,4}. - Add the flags you need in the flags field, such as
gifor a global, case-insensitive search. - Paste realistic sample text into Test String, including the edge cases you expect to fail.
- Read the matches highlighted in the text and listed under Matches & Groups, adjust the pattern, and repeat until only the right text is selected.
- Check the capture groups listed with each match, and type a replacement with
$1or$<name>in Replace with; the rewritten text appears under Replace Result.
Not sure where to start? The Pattern library menu loads one of 15 common patterns together with its flags, from email addresses, URLs, IPv4 addresses, UUIDs and hex colours to Markdown links, repeated words and stray spaces at the start or end of a line. If the test box is empty, or still holds an earlier sample, a sample text comes with the pattern; if you have pasted your own text, it stays, so the pattern runs against your real data. Treat these as starting points, not validators: the email pattern, for instance, is deliberately practical and does not accept every address the standard allows. The guide to email regex and the guide to numbers, phone numbers and IP addresses show where such patterns stop.
Capture groups and find-and-replace
Wrap part of a pattern in parentheses to capture it, and this tester lists every group beside its match - numbered Group 1, Group 2 and so on, plus any named group written (?<name>...). That is how you pull the year, an area code or a file extension out of a match instead of only confirming that it matched. Type something in the Replace with field to rewrite matches on the spot: $1 inserts the first group, $<name> a named one, $& the whole match, and $$ a literal dollar sign.
The flags and what they change
| Flag | Effect | When you need it |
|---|---|---|
g | Find every match, not just the first | Replacing or counting all occurrences |
i | Ignore case | Matching user input, email addresses, tags |
m | ^ and $ match at every line | Working line by line through a log or a list |
s | . also matches a newline | Capturing a block that spans several lines |
u | Full Unicode mode | Emoji, accents, and non-Latin scripts |
y | Sticky - match only at the current position | Writing a tokeniser or parser |
The tokens you will use most
| Token | Meaning |
|---|---|
\d \w \s | A digit, a word character, a whitespace character |
. | Any character except a newline, unless the s flag is set |
^ $ | Start and end of the string, or of each line with m |
* + ? | Zero or more, one or more, zero or one |
{2,5} | Between two and five repetitions |
[abc] [^abc] | Any one of these characters, or anything but these |
(...) (?:...) | Capturing group, non-capturing group |
\b | A word boundary - the fix for matching whole words only |
What people build regexes for
- Validating email addresses, phone numbers, postcodes and identity numbers in forms.
- Extracting IP addresses, status codes, timestamps or user IDs from log lines.
- Search and replace across a codebase, and refactors your editor cannot do literally.
- URL routing and redirect rules in a framework, a web server or a CDN.
- Cleaning scraped or imported data before it reaches a database.
- Enforcing password composition rules on the client side.
Mistakes that cost the most time
- Greedy quantifiers.
.*runs to the end of the line. Use.*?or a negated class such as[^"]*to stop earlier. - Unescaped metacharacters. A literal dot, plus, question mark or slash needs a backslash before it.
- Forgetting the
gflag and wondering why only the first occurrence changed. - Catastrophic backtracking. Nested quantifiers like
(a+)+can hang on a long non-matching input. - Over-strict email patterns. Real addresses contain plus signs, dots and international characters; keep the check loose and confirm by email.
- Trying to parse HTML. Use a parser for nested structures - regex cannot count opening and closing tags.
A note on regex flavours
This tester uses your browser's JavaScript engine, which is the right target if the pattern will run in a web page, in Node.js or in a JSON schema. PCRE, Python, Go and PostgreSQL differ in details such as lookbehind support, named group syntax and Unicode property escapes. Test a pattern in the environment where it will actually run before you rely on it.
Nothing you paste is sent anywhere
The pattern and your sample text stay in the browser. That matters because test data is usually real data - log excerpts, customer records, sample emails - and none of it should end up on someone else's server.
The same pattern in Python, Java, C#, PHP and Go
Once a pattern works here it usually drops into another language with only the wrapper changing. The differences that bite are how backslashes are escaped in string literals and which engine features exist.
| Language | Test for a match | Watch out for |
|---|---|---|
| Python | re.search(r'\d{4}', text) | Use raw strings; named groups are written (?P<name>...) |
| Java | Pattern.compile("\\d{4}").matcher(text).find() | Double the backslashes; matches() needs the whole string to match |
| C# / .NET | Regex.IsMatch(text, @"\d{4}") | Verbatim @ strings avoid double escaping |
| PHP | preg_match('/\d{4}/', $text) | PCRE: delimiters are required, add u for UTF-8 |
| Go | regexp.MustCompile(`\d{4}`).MatchString(text) | RE2 engine: no lookbehind and no backreferences |
Related tools
Patterns usually operate on text from somewhere else. Format a payload with the JSON formatter, decode an escaped value with the URL decoder, read a token with the JWT decoder, and turn matched epoch values into dates with the timestamp converter.