Regex Tester

Test regular expressions with live match highlighting, captured groups and match positions. Quick-insert buttons for common patterns

Quick Patterns

Matches: 9
Highlighted Matches:
The quick brown fox jumps over the lazy dog
Match Details:
Match 1 at index 0:
"The"
Match 2 at index 4:
"quick"
Match 3 at index 10:
"brown"
Match 4 at index 16:
"fox"
Match 5 at index 20:
"jumps"
Match 6 at index 26:
"over"
Match 7 at index 31:
"the"
Match 8 at index 35:
"lazy"
Match 9 at index 40:
"dog"

What the Tool Tests

Type a regular expression in the pattern field, paste your test string below, and the tool runs the regex against the string with whatever flags you've enabled. Matches highlight in yellow inline so you can see exactly which characters got picked up; below the test string, a list shows each match with its start position and any captured groups in parentheses. The pattern compiles on every keystroke, so you get immediate feedback when a syntax error breaks the expression - the error message tells you which part of the pattern is invalid.

Quick-insert presets cover common patterns: email address, URL, phone number, IPv4, date (YYYY-MM-DD), hex colour, alphanumeric username, strong password requirement. Each one is a working regex you can use as-is or modify. The 'strong password' pattern is a good teaching example: it requires lowercase, uppercase, digit, special character, and minimum 8 characters - written with positive lookaheads (?=...) which is one of the trickier regex features to write from memory.

What the Flags Actually Do

g (global): without it, the regex stops after the first match. With it, the regex finds every match in the string. This is the flag you want 90% of the time when extracting or replacing patterns. i (case-insensitive): /hello/i matches 'Hello' and 'HELLO'. Useful for human-input data where capitalisation is unreliable. m (multiline): changes the meaning of ^ and $ from 'start/end of string' to 'start/end of any line'. Important when working with multi-line text. s (dotall): makes the dot character (.) match newlines, which it doesn't by default. Critical when matching across line breaks.

The most common bug in newcomer regex is forgetting g and getting only the first match. The second most common is using . expecting it to match everything, then being surprised by newlines. Toggle s and the issue goes away. Test all four flags on the same pattern to see how the matches change; this is faster than reading documentation about flag behaviour.

Capture Groups and Why They Matter

Parentheses in a regex create capture groups - the part of the match you can extract separately. /(\d{4})-(\d{2})-(\d{2})/ matched against '2026-04-27' captures three groups: '2026', '04', '27'. The tool displays these underneath each match so you can verify your groups are pulling the right data. This is essential for parsing structured text: log files, version numbers, dates, URLs.

Non-capturing groups (?:...) match the same content but don't store the capture, which is faster for the regex engine and cleaner when you only need to group for repetition. Named groups (?<name>...) let you reference matches by name in some languages (Python, JavaScript ES2018+, .NET). The tool shows numbered groups; switching to named groups in production code makes the code much more readable. The [URL parser](/json-formatter) is a good companion when working with structured data - regex extracts, parser validates structure.

Common Regex Quick Reference

PatternMatchesExample
\dAny digit (0-9)2026 has 4 digits
\wWord character (a-z, A-Z, 0-9, _)user_123
\sWhitespace (space, tab, newline)splits words
[abc]Any of a, b, or cmatches single letters
+One or more of previous\d+ matches '123'
*Zero or more of previousa* matches '' or 'aaa'
?Zero or one (optional)colou?r matches both spellings
^Start of line/string^Hello
$End of line/stringWorld$

Frequently Asked Questions

What flavour of regex does the tester use?

JavaScript regex (ECMAScript), since the tool runs in the browser. JS regex is similar to PCRE but has differences: lookbehinds need ES2018+, possessive quantifiers don't exist, the s/dotall flag is ES2018+. If you're writing regex for Python, Java, or PHP, the basic syntax transfers but specific features may differ. For 90% of patterns (digits, words, anchors, quantifiers, character classes), JS regex is portable to anywhere.

Why doesn't my pattern match what I expect?

Most common causes: missing g flag (only finds first match), greedy quantifiers (* and + match as much as possible; use *? and +? for non-greedy), unescaped special characters (. + ? * ( ) [ ] { } ^ $ | \ all need escaping with \ if you want the literal character), or the pattern matching whitespace differently than expected (spaces vs \s vs newlines).

What's the difference between [a-z] and \w?

[a-z] matches only lowercase letters. \w matches letters (a-z, A-Z), digits (0-9), and underscore. Use \w when you want 'word characters' (variable names, usernames). Use [a-z] when you specifically want lowercase only. \w in JavaScript uses ASCII; for Unicode letter matching, you need the u flag and a Unicode property pattern.

Can regex handle nested HTML or JSON?

Officially no - regex can't match arbitrarily nested structures (this is a well-known computer science limitation, related to regular languages vs context-free languages). In practice, regex can handle simple cases of HTML/JSON parsing, but breaks on edge cases like quoted strings containing brackets, or comments containing tags. For real HTML or JSON, use a proper parser; for stripping a simple tag from known clean input, regex is fine.

How do I match a literal dot or backslash?

Escape with backslash. Match a dot: \. Match a backslash: \\. Match a forward slash: \/. The pattern field shows your input as raw, so \. is what you type. In JavaScript code, you'd double-escape (`\\.` in a string literal) but the tester removes that layer of indirection.

More tools β†’