Regex Tester
Test JavaScript regular expressions in real time. Paste a pattern, see every match highlighted, and copy the result when you're done.
TL;DR. Type a pattern and flags on the left, paste the text you want to search on the right, and every match lights up with its index and any named groups. The engine is the same JavaScript RegExp you'd use in Node or the browser, so if it works here it works in your code. Click a preset below to load a tested pattern for emails, URLs, phone numbers, IPs, dates, or hex colors.
How to use the regex tester
- Pick a starting pattern. Click a preset (Email, URL, US Phone, IPv4, ISO Date, Hex Color) or type your own into the Regex Pattern input. The slashes on either side are part of the UI, not the pattern — don't type them yourself.
- Set your flags.
gfor every match,ifor case-insensitive,mfor multi-line anchors,sto let.match newlines,ufor full Unicode (required when the input contains emoji). Combine them — for examplegi. - Paste real data into the test string. A pattern that matches a hand-written example can still fail in production because of smart quotes, trailing whitespace, or encoding differences. Paste the actual log line, CSV row, or user input you need to cover.
- Read the match list. Each card shows the matched text, its index, and any named groups you captured with
(?<name>...). Up to 1000 matches are displayed — enough to validate any realistic pattern. - Copy it into your code. When you paste the pattern into a
new RegExp("...")constructor, double every backslash —\din the tester becomes"\\d"in a string literal. Literal regex syntax (/pattern/flags) does not need the extra escape.
Regex cheatsheet
Every pattern is built from these building blocks. Keep this table open while you experiment.
| Token | Meaning |
|---|---|
| . | Any character except newline (add s flag to include newlines) |
| \d \D | Digit / non-digit |
| \w \W | Word character [A-Za-z0-9_] / non-word |
| \s \S | Whitespace / non-whitespace |
| ^ $ | Start / end of string (or line with m flag) |
| \b \B | Word boundary / non-boundary |
| * + ? | Zero-or-more / one-or-more / optional |
| {n} {n,m} | Exactly n / between n and m repetitions |
| [abc] [^abc] | Character class / negated class |
| (x) (?:x) | Capturing / non-capturing group |
| (?<name>x) | Named capturing group |
| (?=x) (?!x) | Positive / negative lookahead |
| (?<=x) (?<!x) | Positive / negative lookbehind |
| x|y | Alternation (match x or y) |
Common patterns, ready to paste
- Email (loose, good for UX validation):
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}. Do not use this for authoritative deliverability — the RFC grammar is far wider than anything regex can express cleanly. - URL:
https?://[^\s)]+. Stops at whitespace or a closing parenthesis so it plays well with Markdown link syntax. - US phone number:
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}. Covers (415) 555-0133, 415.555.0133, and 415-555-0133. - IPv4 address:
\b(?:\d{1,3}\.){3}\d{1,3}\b. Fine for extracting candidates; do a numeric range check afterwards. - ISO date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2}. - Hex color:
#(?:[0-9a-fA-F]{3}){1,2}\b. Matches both#f0aand#ff00aa.
Frequently asked questions
What is a regex tester and when should I use one?+
Which regex flavor does this tool use?+
What do the g, i, m, s, u, y flags do?+
Why does my pattern work here but fail in my backend code?+
Can regex catastrophically backtrack and freeze the tool?+
Do you send my regex or test string to a server?+
Related developer tools
- JSON Formatter
Pretty-print and validate JSON
- Extract URLs
Pull all URLs out of any text
- Hash Generator
MD5 / SHA-1 / SHA-256 in the browser
- Base64 Converter
Encode and decode Base64