Text 🔒 Runs in your browser — no data sent to servers

Regex Tester

Test regular expressions live: matches, capture groups and replace, with a library of 15 ready-made patterns.

/ /
Test String
Matches & Groups
Matches appear here...

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.

Diagram: the pattern (\d{4})-(\d{2})-(\d{2}) matching 2026-09-17, its capture groups $1, $2 and $3, and the replacement $3/$2/$1 producing 17/09/2026.Pattern(\d{4})-(\d{2})-(\d{2})TextMatchv1.8·2026-09-17$1$2$3$1 = 2026$2 = 09$3 = 17Replace with$3/$2/$1v1.8 17/09/2026
Each pair of parentheses captures part of the match as a numbered group. A replacement can reuse the groups in any order, so $3/$2/$1 turns an ISO date into day/month/year.

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

  1. Enter your pattern without the surrounding slashes - for example [a-z]+\d{2,4}.
  2. Add the flags you need in the flags field, such as gi for a global, case-insensitive search.
  3. Paste realistic sample text into Test String, including the edge cases you expect to fail.
  4. Read the matches highlighted in the text and listed under Matches & Groups, adjust the pattern, and repeat until only the right text is selected.
  5. Check the capture groups listed with each match, and type a replacement with $1 or $<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

FlagEffectWhen you need it
gFind every match, not just the firstReplacing or counting all occurrences
iIgnore caseMatching user input, email addresses, tags
m^ and $ match at every lineWorking line by line through a log or a list
s. also matches a newlineCapturing a block that spans several lines
uFull Unicode modeEmoji, accents, and non-Latin scripts
ySticky - match only at the current positionWriting a tokeniser or parser

The tokens you will use most

TokenMeaning
\d \w \sA 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
\bA 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 g flag 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.

LanguageTest for a matchWatch out for
Pythonre.search(r'\d{4}', text)Use raw strings; named groups are written (?P<name>...)
JavaPattern.compile("\\d{4}").matcher(text).find()Double the backslashes; matches() needs the whole string to match
C# / .NETRegex.IsMatch(text, @"\d{4}")Verbatim @ strings avoid double escaping
PHPpreg_match('/\d{4}/', $text)PCRE: delimiters are required, add u for UTF-8
Goregexp.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.

Guides