Regex Tester
Test JavaScript regular expressions with live match highlighting, group capture display, and replacement preview.
How to use Regex Tester
- Enter your regular expression in the pattern box.
- Add flags (g, i, m, s, u, y) — the global flag is on by default for match-all behaviour.
- Paste the text you want to test against in the larger area below.
- Matches highlight in real time. Capture groups and named groups appear underneath.
How a regular expression actually matches
A regex is a tiny program. The engine walks your text one position at a time, trying to satisfy the pattern from that point; when a piece of the pattern fails, it backtracks and tries another interpretation. Understanding that walk is the difference between patterns that work and patterns that almost work. Because the engine doing that walk is the very same one shipped in your browser, what lights up here is exactly what will match in Node or any modern browser — no server round-trip, no flavour mismatch.
A real pattern, character by character
Take /^\d{4}-\d{2}-\d{2}$/, a strict ISO-date matcher. ^ anchors the match to the start of the string, so nothing may precede the date. \d{4} demands exactly four digit characters — the year. The literal - must follow. \d{2} takes two digits for the month, another hyphen, two more digits for the day, and $ anchors the end. Against 2026-06-11 every piece consumes its text and the match succeeds; against 2026-6-11 the second \d{2} finds only one digit before the hyphen and the whole match fails. Note what it does not check: 9999-99-99 passes, because regex validates shape, not meaning.
Flag cheatsheet
- g — global, return all matches instead of just the first
- i — case-insensitive
- m — multiline; ^ and $ match at line boundaries
- s — dotAll; "." also matches newline characters
- u — Unicode; enables
\p{...}property escapes - y — sticky; matches only at lastIndex (advanced)
Capture groups: pulling data out of a match
Parentheses do double duty: they group, and they capture. /(\d{4})-(\d{2})-(\d{2})/ matches the same dates as before but also exposes the year, month, and day as groups 1, 2, and 3. Named groups read better in real code: /(?<year>\d{4})-(?<month>\d{2})/ lets you write match.groups.year instead of remembering an index. If you need parentheses only for grouping — say, around an alternation — use a non-capturing group (?:...) so you do not pollute the group numbering.
Catastrophic backtracking: the pitfall that freezes pages
Backtracking is usually cheap, but nested quantifiers can make it exponential. The pattern (a+)+b against a string of 30 a characters and no b forces the engine to try every way of splitting the run between the inner and outer + — roughly 2^30 attempts before it can report failure. The fix is to remove the ambiguity: here, a+b matches the same strings with zero risk. As a rule, never apply a quantifier to a group whose contents can already repeat, and be suspicious of alternations whose branches overlap, like (\w|\d)+. This matters in production because user-supplied input hitting a vulnerable pattern is a denial-of-service vector (ReDoS).
Patterns worth memorizing
Email-ish: /^[\w.+-]+@[\w-]+\.[\w.-]+$/. URL-ish: /https?:\/\/\S+/g. Whitespace squash: /\s+/g. None are perfect — real-world inputs always contain edge cases. Use this playground to confirm before shipping a pattern to production, and prefer an anchored, specific pattern over a clever general one: the next person to read it will thank you.
Related tools
- Find & Replace — apply a pattern across text and rewrite the matches in one pass.
- Email Extractor — pull every address out of a blob of text without writing the regex yourself.
- JSON Formatter — pretty-print the structured data your patterns often parse.
- URL Encoder — encode or decode the URLs your patterns match against.
Frequently asked questions
Which regex flavour does this use?
How do I match across newlines?
My regex hangs the page — why?
Can I safely test against real log data or production strings?
Can I see capture groups?
What is the difference between greedy and lazy quantifiers?
How do I match a literal dot, plus, or question mark?
What does \b actually match?
Related tools
More tools you might find useful in the same flow.
Base64 Encoder
Base64 encoder and decoder online: convert text to Base64 or decode Base64 strings back to readable text. UTF-8 safe, instant, and free to use with no signup.
Hash Generator
Hash generator online: create MD5, SHA-1, SHA-256, and SHA-512 hashes from any text instantly. Free, with all hashing done locally in your own browser.
Cron Parser
Cron expression parser — paste any cron schedule to get a plain-English explanation plus its next run times. Free, instant, and works right in your browser.
JSON Formatter
Free JSON formatter, validator, and minifier with line/column error reporting. Sensitive payloads stay on your device — nothing is sent to a server.
Built by Muhammad Tahir · About