Developer Tools

Free Regex Tester Online

Test regular expressions with live match highlighting. Supports JavaScript and Python.

What is a regex tester?

A regex tester is a tool that lets you write and test regular expressions (regex) against real text, with live match highlighting. Instead of adding console.log statements to your code, you can iterate on your pattern in real time, see every match highlighted in color, and debug capture groups before copying the final expression into your project.

This tester uses JavaScript's built-in ECMAScript RegExp engine — the same engine your browser and Node.js use. Patterns work exactly as they would in your JavaScript or TypeScript code. Advanced features like lookahead ((?=...)), lookbehind ((?<=...)), named capture groups, and unicode are all supported. Use the regex cheat sheet below as a quick reference.

How to use the regex tester

  1. 1
    Enter your pattern

    Type your regular expression in the pattern field between the / delimiters. Or click a Quick Pattern button (Email, URL, IPv4, Digits...) to start with a proven template.

  2. 2
    Set flags

    Toggle flags using the g, i, m, s buttons. Hover over each flag to see what it does. The g (global) flag is enabled by default to find all matches.

  3. 3
    Paste your test string

    Enter the text you want to match against. Matches are highlighted in real time with color-coded marks — each match gets a distinct color up to 1000 matches.

  4. 4
    Review match details

    The match details panel shows every match with its position [start–end] and any named capture group values.

  5. 5
    Test replacements

    Enable the Replace toggle to test substitutions. Use $1, $2 for numbered groups or $<name> for named groups.

  6. 6
    Export to CSV

    Click Export CSV to download all matches with position data and group values as a spreadsheet.

Regex flags explained

Flags modify the behaviour of a regex pattern without changing the pattern itself. In JavaScript, flags are appended after the closing slash: /pattern/flags. The most important flags to understand:

FlagNameEffect
gGlobalFind all matches in the string. Without g, only the first match is returned.
iIgnore caseCase-insensitive matching. /hello/i matches "Hello", "HELLO", "hElLo".
mMultilineMakes ^ and $ match start/end of each line, not the whole string. Useful for line-by-line processing.
sDotallMakes . match newline characters too. Without s, . matches any character except \n.
uUnicodeEnables full Unicode matching. Required for matching emoji and characters outside the BMP (> U+FFFF).
yStickyMatches only from lastIndex — does not search forward. Useful for tokenizers that process a string sequentially.
dIndicesAdds start/end character indices to each match result. Useful when you need precise cursor positions.

Regex metacharacters cheat sheet

These are the building blocks of every regular expression. Memorising them lets you read and write most patterns without needing a reference:

TokenMatchesExample
.Any character except newline (unless s flag)/c.t/ matches "cat", "cut", "c3t"
\dAny digit 0–9/\d+/ matches "42", "100"
\wWord character [a-zA-Z0-9_]/\w+/ matches "hello_world"
\sWhitespace (space, tab, newline)/a\sb/ matches "a b"
\D \W \SUppercase = inverse of lowercase version/\D/ matches any non-digit
^Start of string (or line with m flag)/^hello/ matches only at line start
$End of string (or line with m flag)/end$/ matches only at line end
*Zero or more of previous token/a*/ matches "", "a", "aaa"
+One or more of previous token/a+/ matches "a", "aaa" (not "")
?Zero or one (makes previous optional)/colou?r/ matches "color" and "colour"
{n,m}Between n and m repetitions/\d{2,4}/ matches 2 to 4 digits
[abc]Character class — any of a, b, c/[aeiou]/ matches any vowel
[^abc]Negated class — any except a, b, c/[^0-9]/ matches any non-digit
(…)Capture group/(\w+)@/ captures username in email
(?:…)Non-capturing group/(?:https?):\/\// groups without capturing
(?=…)Lookahead — match if followed by/\w+(?=\()/ matches function names
(?<=…)Lookbehind — match if preceded by/(?<=\$)\d+/ matches amount after $
a|bAlternation — a or b/cat|dog/ matches "cat" or "dog"

Most useful regex patterns

Email address[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}

Covers 99% of valid email formats

URL (http/https)https?:\/\/[\w\-]+(\.[\w\-]+)+[\S]*

Matches most web URLs

IPv4 address\b(?:\d{1,3}\.){3}\d{1,3}\b

Does not validate 0–255 range

ISO date (YYYY-MM-DD)\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])

Validates month and day ranges

HEX color code#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\b

Matches both 3 and 6 character formats

Digits only^\d+$

Full string must be numeric

Whitespace (trim)^\s+|\s+$

With g flag — remove leading/trailing spaces

Common regex mistakes and how to avoid them

Catastrophic backtracking

Patterns like /(a+)+b/ applied to "aaaaaaaaaaac" cause exponential backtracking — the engine tries every possible combination of ways to group the "a"s before concluding there is no match. This can freeze a browser tab or crash a Node.js process. Avoid nested quantifiers (a+)+ and alternations that can match the same character in multiple ways.

Fix: Use possessive quantifiers or atomic groups where available, or rewrite the pattern to avoid ambiguity. Test potentially slow patterns against long non-matching strings.

Greedy quantifiers consuming too much

By default, quantifiers like *, +, and ? are greedy — they match as much as possible. The pattern /<.+>/ against "<b>bold</b>" matches the entire string including both tags, not just the first tag. The greedy + consumed everything up to the last >.

Fix: Make quantifiers lazy by appending ?: /<.+?>/ matches the shortest possible sequence. Or use a negated character class: /<[^>]+>/ matches any sequence that excludes > — more precise and faster.

Forgetting to escape special characters

In regex, the characters . * + ? ^ $ { } [ ] | ( ) have special meaning. Matching a literal period in a domain name requires \. not . — an unescaped . matches any character. /example.com/ matches "exampleXcom", "example-com", and "example.com" equally.

Fix: Escape any character that should be treated literally: /example\.com/. If unsure, escape all non-alphanumeric characters when you mean them literally.

Using regex for full email or URL validation

A truly correct email regex that validates every edge case in RFC 5321 is several thousand characters long. Patterns that look correct will reject valid addresses (those with + signs, subdomain labels, or international domain names) or accept invalid ones.

Fix: Use regex for basic format screening, not authoritative validation. The gold standard for email validation is to send a confirmation email — if it arrives, the address is valid. For URLs, use the URL constructor: new URL(str) throws on invalid URLs.

Not anchoring patterns that should match the whole string

/\d{4}/ matches "ab1234cd" because there are four digits somewhere in the string. If you want to verify the entire string is a 4-digit number, you must anchor: /^\d{4}$/.

Fix: Use ^ (start of string) and $ (end of string) anchors when your pattern should match the complete input, not a substring within it. With the m flag, use \A and \Z in languages that support them for true string boundaries.

Regex across programming languages — key differences

Regex syntax is largely standardised but not identical across languages. This tester uses the JavaScript ECMAScript engine. Here is what changes when you move between environments:

Python (re module)

Uses raw strings r"..." to avoid double-escaping backslashes. Supports named groups (?P<name>...). re.match() anchors at start automatically; use re.search() for substring matching. The re.VERBOSE flag allows comments and whitespace inside patterns.

Go (regexp)

Uses RE2 syntax — no backreferences, no lookahead, no lookbehind. Guaranteed linear-time matching prevents catastrophic backtracking by design. Named groups use (?P<name>...). All patterns compiled with regexp.Compile() are goroutine-safe.

Java (java.util.regex)

Requires double-escaping backslashes in string literals: "\d+" for d+. Supports possessive quantifiers (a++) and atomic groups ((?>...)) for preventing backtracking. Pattern objects are thread-safe and should be compiled once and cached.

PHP (PCRE)

Patterns are strings with delimiters: /pattern/flags or #pattern#flags. Supports all PCRE features including atomic groups, possessive quantifiers, and conditionals. preg_match() returns the count of matches, not a boolean — check with === 1.

Ruby

Regex is a first-class type: /pattern/. Supports named captures with (?<name>...). The =~ operator matches and sets $~ to the MatchData. String#match returns nil on no match, making conditional use idiomatic.

FAQ

Common questions

What regex flavour does this tester use?

This tester uses JavaScript's built-in RegExp engine, which follows the ECMAScript specification. It supports most common regex features including lookaheads, named groups (?<name>...), and Unicode. It does not support lookbehinds in all browsers or PCRE-specific syntax.

What do the flags mean?

g (global) — find all matches instead of stopping at the first. i (insensitive) — ignore case when matching. m (multiline) — make ^ and $ match the start/end of each line, not just the whole string. s (dotall) — make . match newline characters as well.

How do I use named capture groups?

Use the syntax (?<name>pattern). For example, (?<year>\d{4})-(?<month>\d{2}) will capture year and month as named groups. The match details panel shows captured group names and values.

How does replacement work?

Enable the Replace toggle and enter a replacement string. Use $1, $2... to reference capture groups by number, or $<name> for named groups. For example, replacing (\w+) (\w+) with $2 $1 swaps two words.

Why does my regex cause an infinite loop?

Zero-length matches (like \b or a* on empty input) can cause infinite loops with the global flag. This tester automatically advances the cursor to prevent hanging. If you get unexpected results, try removing the g flag.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers (*, +, {n,m}) match as much as possible. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible. Example: given "<b>bold</b>", the pattern <.*> greedily matches the entire string, while <.*?> matches only "<b>". Use lazy quantifiers when you need the shortest possible match between delimiters.

How do lookaheads and lookbehinds work?

Lookaheads and lookbehinds are zero-width assertions — they check a position without consuming characters. Positive lookahead (?=...) asserts what follows. Negative lookahead (?!...) asserts what does not follow. Positive lookbehind (?<=...) asserts what precedes. Example: \d+(?= dollars) matches a number only when followed by " dollars".

How do I match a literal dot, bracket, or other special character?

Escape it with a backslash: \. matches a literal dot, \( matches a literal parenthesis, \$ matches a dollar sign. Inside a character class [ ], most special characters lose their meaning — [.] matches a literal dot without escaping. Characters that must always be escaped outside a class: . * + ? ^ $ { } [ ] ( ) | \.

More in Developer Tools