Quick Examples
Mode
Free online regex pattern tester for JavaScript-style regular expressions. Test regex patterns, preview color-coded matches, inspect capture groups, and replace matched text — all instant, all in your browser.
Quick Examples
Mode
A regular expression — commonly called a regex or regexp — is a compact sequence of characters that defines a search pattern. Instead of writing custom loops to scan strings character by character, a well-written regex expresses the same logic in a single line that any language can execute natively.
At its core, regex uses three building blocks: literals (characters that match themselves, e.g. the letter a), metacharacters (special symbols like .\d\w that match classes of characters), and quantifiers (+*? that control how many times a part must repeat).
Regex is supported natively in JavaScript, Python, Java, C#, Go, Ruby, PHP, and nearly every other language. The syntax and engine behaviour differ slightly between languages — this tool uses the JavaScript ECMAScript engine, the same engine running in your browser and in Node.js.
Every keystroke triggers a match using the browser's native RegExp object — no server round-trip, no delay. The results update live as you type your pattern or edit your test string.
In Match mode the tool highlights every match directly inside the test string with cycling colours (yellow, green, blue, purple) so you can tell multiple matches apart at a glance. The Match Details panel shows each match's full value, start and end position, character length, and any capture group values.
Switch to Replace mode to type a replacement string and instantly preview what the text looks like after the substitution. Use $1, $2, and so on to insert captured group values into the replacement — the same syntax used by JavaScript's String.prototype.replace().
gGlobal
Find all matches, not just the first. Without g, the engine stops after the first match — even if more exist. Enabled by default in this tool.
iCase-Insensitive
Match letters in any case. The pattern hello with i also matches Hello, HELLO, or any mixed case.
mMultiline
Makes ^ and $ match the start and end of each line, not just the whole string. Essential when testing patterns against multi-line logs.
sDotAll
Lets the dot . match newline characters. Without this flag, . skips line breaks, making it impossible to match across lines with a simple dot.
uUnicode
Enables full Unicode matching and stricter pattern parsing. Required for matching emoji, non-Latin scripts, or Unicode property escapes like \p{L}.
These patterns cover the most frequent developer use cases. Click any Quick Example button above to load them instantly into the tester.
Matches the local part before @, the domain, and a two-or-more-character top-level domain. Works for most standard addresses. More precise email validation should be done server-side.
The s? makes the s optional, matching both http and https. [^\s]+ consumes everything up to the next whitespace character.
\d matches any digit 0–9. The + quantifier requires one or more digits, so it finds complete numbers rather than individual digits.
Curly brace quantifiers like \d{4} require exactly 4 digits. This pattern finds ISO 8601 date strings. It does not validate whether the values are a real calendar date — use a date library for that.
This rewrites 2024-01-15 as 15/01/2024. Each pair of parentheses captures a group; $1, $2, $3 reference them in the replacement. Switch to Replace mode in the tool above to try it.
Most regex debugging sessions come down to a small set of repeating mistakes. Knowing them saves hours.
Characters like .+*?()[]{}\^$| have special meaning in regex. If you want to match them literally, escape with a backslash: \. matches a real dot, not any character.
Without g, the engine returns only the first match and stops. If you expect multiple results and get just one, enable the global flag.
By default, + and * are greedy — they match as many characters as possible. The pattern <.+> on the string <b>bold</b> will match the entire string, not just <b>. Add ? to make it lazy: <.+?>.
^ anchors to the start of the string (or line, with m); $ anchors to the end. Using them when you do not mean to makes the pattern match nothing if the string has leading or trailing content.
By default regex is case-sensitive. The pattern Error will not match error or ERROR. Enable the i flag when case should not matter.
Start simple and add complexity gradually
Begin with the simplest pattern that matches one known input, then widen it. Large patterns written all at once are almost impossible to debug.
Be as specific as possible
Prefer [0-9] or \d over . when you know you want digits. Overly broad patterns produce false matches in unexpected inputs.
Use non-capturing groups when you don't need backreferences
(?:...) groups characters without storing a capture. This keeps the group list clean and can improve performance in loops.
Test against edge cases, not just happy paths
After your pattern matches the expected input, test it against empty strings, very long inputs, Unicode characters, and inputs with special characters to catch unintended matches.
Prefer word boundaries over anchors for token matching
\b matches at a word boundary without consuming characters. \bcat\b matches cat but not concatenate or tomcat.
Regex is a tool, not always the solution
For complex structured data like full HTML, deeply nested JSON, or multi-line templated formats, a dedicated parser is more reliable and maintainable than regex.
A regex tester is a tool that lets you write a regular expression pattern and immediately see which parts of your test text it matches — without writing code, running a script, or switching between tools. It shortens the feedback loop when writing or debugging regex patterns. This tool uses the JavaScript RegExp engine so the results match exactly what you would get in a browser or Node.js application.
Testing a regex online is simple: paste or type your pattern into the Regex Pattern field, enter the text you want to test in the Test String area, then enable whichever flags apply (for example, g to find all matches and i to ignore case). Results update instantly — matched text is highlighted in colour, the total match count appears in the summary bar, and each individual match is listed with its position and any capture group values. No account or installation is required.
Click the Replace tab above the pattern input. Enter your regex pattern, paste your test string, then type a replacement string. You can use $1, $2… to insert capture group values into the replacement. The result is shown instantly. Click Copy Result to copy the transformed string.
g (global) finds all matches. i (case-insensitive) ignores letter case. m (multiline) makes ^ and $ match line boundaries. s (dotAll) lets the dot match newlines. u (Unicode) enables full Unicode support including property escapes like \p{L}.
Capture groups are portions of the pattern wrapped in parentheses ( ). They capture the matched text separately from the full match. In Match mode, groups appear in the Match Details panel. In Replace mode, reference them with $1, $2, etc.
Invalid regex means the pattern itself has a syntax error — for example, an unclosed parenthesis (, an unescaped special character, or an invalid quantifier like {2,1} (min greater than max). The error message below the pattern field explains exactly what went wrong. Not matching is different — the pattern is valid but doesn't find anything. Common causes: missing g flag (only the first match is returned without it); missing i flag for case-insensitive text; unescaped special characters such as \. for a literal dot; or anchors ^ / $ restricting the match to start or end of string.
Without the g (global) flag, a regex stops after finding the first match and returns only that result. With the g flag enabled, the engine scans the entire string and returns every occurrence. For example, the pattern \d+ without g finds only the first number in a sentence; with g it finds all numbers. The global flag is almost always what you want when processing real-world data. This tester defaults g to on so you see all matches immediately.
Yes. Everything runs inside your browser using the native JavaScript RegExp engine. No pattern, test string, or replacement text is ever sent to any server. Nothing is logged, stored, or shared.
This tool uses the JavaScript ECMAScript RegExp engine — the same engine in Chrome, Firefox, Safari, Edge, and Node.js. Results match what you would get when writing regex in JavaScript code. If you are building for a Python, PHP, or Ruby backend, note that those engines have slightly different syntax and behaviour.