How to Test a Regex Online (Free Guide with Examples)
You're writing a regex to pull phone numbers out of a contact list, or to validate the email field on a signup form, or to clean up a log file. You type the pattern, run it, and it either matches nothing or matches too much — and you have no idea why. A regex tester solves that in ten seconds: you paste the pattern, paste the sample text, and see every match light up in real time. This guide walks through how to do it well, with copy-paste examples you can run right now.
What Is a Regex?
A regex (short for regular expression) is a compact pattern language for finding, extracting, and replacing text. Instead of writing “find any sequence of digits, dash, more digits”, you write \d+-\d+ and the regex engine does the rest. Every major programming language — JavaScript, Python, PHP, Go, Java, Ruby — ships with a regex engine, and tools like grep, sed, VS Code find-and-replace, nginx config rules, and Google Sheets REGEXEXTRACT all understand regex too. Learning it once pays off everywhere.
How to Test a Regex Online, Step by Step
Open our free Regex Tester. Then:
- Type your pattern into the Pattern field. Start simple —
\d+matches any run of digits. - Turn on flags you need.
gfinds all matches,iignores case,mmakes^and$work per line. Click any flag pill to toggle it. - Paste your test text into the Test string box. Matches highlight in purple as you type.
- Check the Matches list. Every match is numbered with its position and capture groups, so you can confirm the regex extracts exactly what you expect.
- Share or copy. Click Copy regex to grab the literal
/pattern/flags, or Share link to send a URL that restores the whole session.
Ten Regex Patterns You'll Actually Use
Copy these directly into the tester and see them work:
- Email —
\b[\w.+-]+@[\w-]+(?:\.[\w-]+)+\b - URL —
https?://[\w.-]+\.[\w.-]+\S* - US phone —
\(?\b\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b - IPv4 —
\b(?:25[0-5]|2[0-4]\d|[01]?\d\d?)(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)){3}\b - Hex color —
#(?:[0-9a-fA-F]{3}){1,2}\b - ISO date —
\b\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])\b - UUID v4 —
\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}\b - USD price —
\$\d{1,3}(?:,\d{3})*(?:\.\d{2})? - Leading/trailing whitespace —
^\s+|\s+$ - Repeated words —
\b(\w+)\s+\1\b
The Regex Tester ships with all of these as one-click presets, so you can load them without typing anything.
Flags — What They Mean
Flags change how the regex runs. Get them wrong and your pattern silently misbehaves.
g(global) — finds every match instead of stopping at the first. Almost always what you want for extracting or counting.i(case-insensitive) —/hello/imatches Hello, HELLO, hElLo.m(multiline) — makes^and$match at line breaks, not just start/end of the whole string.s(dotall) — makes.match newlines too. Handy for multi-line blobs.u(unicode) — enables\p{...}property escapes and proper handling of astral characters like emojis.y(sticky) — matches only atlastIndex. Rare; used for tokenizers.
Capture Groups and Named Groups
Parentheses capture. Write (\d{3})-(\d{4}) against 555-1234 and you get back 555 as group 1, 1234 as group 2. Named groups are clearer:(?<area>\d{3})-(?<line>\d{4}) lets you refer to matches by name. Non-capturing groups (?:...)let you group without producing a capture — useful for repeats and alternations you don't want in your output.
The Regex Tester lists every capture group and named group under each match, so you can confirm they're populated the way you expect before using the regex in code.
Replace Mode — Find and Substitute
Switch to the Replace tab and your regex runs against String.replace so you can preview substitutions live. Use $1, $2, etc. to reference capture groups, and $& to reference the whole match. For example:
- Pattern
(\w+)\s(\w+), replacement$2 $1, on John Smith, Jane Doe → Smith John, Doe Jane. - Pattern
\d+, replacement[$&], on Order 42 ships in 7 days → Order [42] ships in [7] days.
Catastrophic Backtracking (aka Why Your Browser Froze)
Some regex patterns have a dark side. Try (a+)+bagainst a long string of a's ending in a different letter — like aaaaaaaaaaaaaaaac. The engine explores billions of ways to split the a's before giving up. The browser tab freezes. This is called catastrophic backtrackingand it's the #1 production bug in regex-heavy apps.
The Regex Tester detects nested quantifiers like (a+)+, (x*)*, and ([a-z]+)* and shows an amber warning before you accidentally ship one. The fix is to rewrite with atomic groups, possessive quantifiers (not in JS), or simply avoid overlapping repeats.
Why Test Regex in the Browser?
Most online regex testers upload your pattern and test string to their servers for processing. That's fine for public patterns, but if you're testing against real user data, production logs, private keys, or internal URLs, you're handing all of that to a third party. Our Regex Tester runs entirely client-side — the JavaScript engine in your browser does all the work. Nothing leaves your device. No network request is made with your pattern or your text.
Client-side also means instant matching. There's no “run” button; the result updates as you type. And because everything runs locally, there are no rate limits and no signup.
Tips for Building Regexes Faster
- Start specific, generalize later. Match one known case first. Then widen with character classes and quantifiers.
- Use
\bword boundaries to stop matches from bleeding into neighboring text. - Prefer non-greedy quantifiers (
*?,+?) when matching content between delimiters — like HTML tags or quoted strings. - Escape special characters in literal text:
.,*,+,?,^,$,(,),[,],{,},|,\. - Test with edge cases. Empty strings, strings with only whitespace, strings with the character you're matching repeated 100 times.
- Use the cheatsheet. The built-in reference inside the Regex Tester has every common token in one place.
Related Tools
- Regex Tester — the tool this guide uses.
- Text Diff Checker — compare before/after when your regex changes text.
- JSON Formatter — often paired when extracting JSON with regex.
- URL Encoder — when your matched URLs need encoding.
Ready to Test a Regex?
Open the Regex Tester and paste your pattern. No signup, no limits, no uploads. Test patterns, preview replacements, share links with teammates — all from the browser.

