Regex Tester
Test regular expressions with instant visual feedback
Regular Expression
Common Patterns
Sample Texts
0 Matches Found
Test Text
Highlighted Matches
Free Online Regex Tester — Test Regular Expressions Instantly
Regular expressions are one of the most powerful tools in a developer's toolkit. They let you search, match, and manipulate text using patterns. But writing the right regex can be tricky — a single misplaced character can change the entire behaviour. That is where a live regex tester becomes essential. Instead of running your code, deploying, and checking logs, you can test your pattern right here and see every match highlighted instantly.
This free Regex Tester supports all six JavaScript regex flags: global (g), case-insensitive (i), multiline (m), dotAll (s), unicode (u), and sticky (y). Type your pattern, paste your test string, and watch matches appear in real time. Every match is colour-coded and numbered. Capture groups are shown separately. You can also use the built-in replace mode to test find-and-replace operations.
Eight common patterns are built in — email, URL, phone number, hex colour, IP address, date, HTML tag, and plain numbers. Four sample texts are provided so you can test patterns instantly. All processing runs in your browser. No data is sent to any server.
Understanding Regex Flags
g — Global
Find all matches in the string, not just the first one. Without this flag, the regex stops after the first match.
i — Case-insensitive
Treat uppercase and lowercase letters as the same. "abc" matches "ABC", "Abc", and so on.
m — Multiline
Make ^ and $ match the start and end of each line, not just the start and end of the entire string.
s — DotAll
Make the dot (.) match newline characters as well. By default, dot matches everything except newlines.
u — Unicode
Enable full Unicode support. Required for matching emoji, CJK characters, and other multi-byte sequences correctly.
y — Sticky
Match only from the position indicated by lastIndex. Useful for tokenisation and lexer implementations.
Common Regex Patterns Explained
Email validation
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} — Matches standard email addresses with alphanumeric local parts and domain names.
URL matching
https?://[\w\-]+(\.[\w\-]+)+[/#?]?.* — Matches HTTP and HTTPS URLs with domain names, paths, and query strings.
Phone numbers
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} — Matches US phone numbers in various formats: (123) 456-7890, 123-456-7890, 123.456.7890.
IP addresses
\b(?:\d{1,3}\.){3}\d{1,3}\b — Matches IPv4 addresses like 192.168.1.1. Does not validate range (0-255).
Dates
\d{4}-\d{2}-\d{2} — Matches dates in YYYY-MM-DD format. Does not validate month or day ranges.
HTML tags
<[^>]+> — Matches opening and closing HTML tags including self-closing tags. Not suitable for full HTML parsing.
Frequently Asked Questions
Is this regex tester free?+
Is my data sent to a server?+
What regex engine does it use?+
Does it support capture groups?+
Can I do find and replace?+
What are the highlight colours?+
Can I copy the regex?+
Does it work on mobile?+
Why greedy matching swallows more than you meant
The single most common regex surprise, and it is a design decision rather than a quirk.
Quantifiers are greedy by default. `*` and `+` consume as many characters as possible while still permitting an overall match, then give characters back only as needed. So `<.*>` applied to "<a><b>" matches the entire string: the dot-star takes everything, backs off to find a final ">", and stops at the last one.
Making the quantifier lazy with a question mark reverses the preference. `<.*?>` takes as little as possible, so it matches "<a>" and then "<b>" separately.
The better habit is often to avoid the dot entirely. `<[^>]*>` says "anything that is not a closing bracket", which expresses the intent directly and cannot overrun. Being specific about what you will accept beats adjusting greediness after the fact.
Reading capture groups instead of guessing
A pattern that matches is only half the answer. What it captured is usually the part you need.
Parentheses create a capture group, numbered left to right by opening bracket. Nested groups make this fiddly to count by hand, which is exactly why inspecting them in a tester is faster than reasoning about them.
Two things catch people. A non-capturing group, written `(?:...)`, groups for the purposes of a quantifier without capturing — so it does not take a number, and every subsequent group shifts. And a group inside an optional section can match overall while that group participated in nothing, giving you an empty or undefined capture.
Named groups help considerably on anything non-trivial. Referring to a value by name rather than position survives you adding a group in the middle six months later.
The backtracking failure that hangs a server
This is the regex problem with genuine production consequences, and it is invisible in small tests.
A backtracking engine explores possibilities. With nested quantifiers, the number of possibilities can grow exponentially with input length. A pattern like `(a+)+b` against thirty "a" characters and no "b" forces the engine through an astronomical number of combinations before concluding there is no match.
On your ten-character test it returns instantly. On a real input it pins a CPU core indefinitely. Where the pattern runs on user-supplied input, that is a denial-of-service route — someone sends a crafted string and your request handler stops responding.
The defences are structural. Do not quantify a group that already contains a quantifier. Replace the dot with a specific character class so alternatives cannot overlap. Anchor the pattern so the engine cannot retry at every position. And test with input far longer than your examples, because length is what exposes it.
When a regular expression is the wrong tool
Knowing where to stop is worth more than any pattern trick.
Nested structures are the hard limit. HTML, XML, JSON and programming languages all nest to arbitrary depth, and regular expressions cannot express arbitrary nesting — it is a property of what they are, not a gap in any implementation. A pattern will work on your examples and fail on real input, which is the worst kind of failure because it passes review.
Email addresses are the famous near-miss. The specification permits quoted strings, comments and address literals, and a pattern that genuinely matches it is pages long and unmaintainable. Check for an at sign with plausible content either side, then send a confirmation message. Delivery is the only validation that means anything.
Where a regex does excel: finding a known pattern in flat text, splitting on a delimiter, validating a format you control such as a product code, and search-and-replace across a codebase. Those are the jobs it was built for, and it does them better than anything else.
How to use the Regex Tester
- Enter your pattern and paste sample text that includes the awkward cases.
- Set the flags deliberately — global for every match, multiline for per-line anchors.
- Check the capture groups, not just whether the whole pattern matched.
- Make quantifiers lazy with a question mark if a match is swallowing too much.
- Test against input much longer than your examples to expose backtracking.
What this tool handles
Live match highlighting
See exactly which characters matched rather than inferring from a yes or no.
Capture group inspection
Every group listed with what it captured, including the ones that came back empty.
Flag control
Global, multiline, case-insensitive and dotAll, each changing behaviour independently.
Runs in your browser
No request is made, so sample data stays on your machine.
Frequently asked questions
Why does my pattern match more than I expected?
▼
What is catastrophic backtracking?
▼
How do I avoid writing one?
▼
Does a regex that works here work in Python?
▼
Why does my capture group come back empty?
▼
What is the difference between the global and multiline flags?
▼
Should I use a regex to parse HTML?
▼
Is a regex the right way to validate an email address?
▼
Is my pattern or test text sent anywhere?
▼
Why does the dot not match my line breaks?
▼
Related Tools You Might Like
Case Converter
Convert text between UPPERCASE, lowercase, Title Case, and more
Password Generator
Generate secure, random passwords with custom options
Word Counter
Count words, characters, paragraphs, and reading time
Base64 Encoder & Decoder
Encode and decode Base64 for text, files, and images with Data URI output
File to Base64
Encode any file type to Base64 or a Data URI, with the MIME type filled in
Base64 to File
Decode a Base64 string into a real file, with the type read from its header bytes
