Try the Regex Tester

Regex Tester β€” Write & Debug Regular Expressions with Live Highlighting

Learn how to write and debug regular expressions using a live tester β€” with syntax reference, real examples for email validation, log parsing, and URL extraction, and tips on greedy vs. lazy matching.

By sadiqbd Β· June 6, 2026

Share:
Regex Tester β€” Write & Debug Regular Expressions with Live Highlighting

Regular expressions are powerful and genuinely hard to get right

Most developers can write a basic regex. Fewer can write one that handles edge cases correctly, and almost nobody can read an unfamiliar regex cold and immediately understand what it matches. The syntax is dense β€” a single misplaced character changes the meaning entirely, and errors fail silently by matching too much, too little, or in unexpected places.

A regex tester lets you write your pattern and see immediately what it matches β€” or doesn't β€” against real input. It's the fastest way to develop, debug, and verify regular expressions.


What a Regex Tester Shows You

A good regex tester gives you:

  • Match highlighting β€” which parts of the input are matched, highlighted inline
  • Capture groups β€” what each group ((...)) captures, shown separately
  • Match count β€” how many matches were found
  • Named captures β€” values of named groups ((?P<name>...))
  • Flags β€” toggle case-insensitive, multiline, global, dotall, and other modes
  • Real-time feedback β€” pattern and matches update as you type

This immediate feedback loop is what makes testing regex interactively so much faster than writing a pattern, running code, reading output, adjusting, and repeating.


Regex Syntax: The Essentials

Literal characters

Most characters match themselves. hello matches the string "hello".

Metacharacters

Characters with special meaning:

Symbol Meaning
. Any character except newline
* 0 or more of preceding
+ 1 or more of preceding
? 0 or 1 of preceding (also makes quantifiers lazy)
^ Start of string (or line in multiline mode)
$ End of string (or line in multiline mode)
\ Escape next character
` `
[] Character class
() Capture group
{} Quantifier {n}, {n,}, {n,m}

Character classes

  • [abc] β€” matches a, b, or c
  • [a-z] β€” any lowercase letter
  • [0-9] β€” any digit
  • [^abc] β€” any character except a, b, c

Shorthand character classes

  • \d β€” digit (0-9)
  • \w β€” word character (a-z, A-Z, 0-9, _)
  • \s β€” whitespace (space, tab, newline)
  • \D, \W, \S β€” negated versions

Anchors

  • \b β€” word boundary
  • \B β€” non-word boundary

Groups

  • (abc) β€” capture group
  • (?:abc) β€” non-capturing group
  • (?P<name>abc) β€” named capture group
  • (?=abc) β€” positive lookahead
  • (?!abc) β€” negative lookahead

How to Use the Regex Tester on sadiqbd.com

  1. Enter your pattern β€” the regex you want to test, without delimiters.
  2. Set flags β€” toggle global (g), case-insensitive (i), multiline (m), dotall (s) as needed.
  3. Enter test input β€” the string or multi-line text you want to match against.
  4. See matches highlighted β€” matches are highlighted in the input in real time.
  5. Check capture groups β€” the panel shows what each group captured from each match.

Iterate: adjust the pattern, watch the matches update, refine until it does exactly what you need.


Real-World Examples

Email validation (basic)

^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$

Test input:

  • user@example.com βœ…
  • user.name+tag@sub.domain.org βœ…
  • invalid@ ❌
  • @nodomain.com ❌
  • no-at-sign.com ❌

The tester shows which addresses match and which don't β€” helpful for identifying edge cases before deploying.

Extracting phone numbers

(\+880|0)[0-9]{10}

Matches Bangladeshi mobile numbers starting with +880 or 0 followed by 10 digits. Test against a block of text β€” the tester highlights every match and shows what each capture group (the country code prefix) contains.

URL extraction from text

https?://[^\s<>"]+

Finds all HTTP/HTTPS URLs in a paragraph of text. The global flag (g) returns all matches. Check the tester's match list to verify it captures full URLs without trailing punctuation.

Log parsing

A server log line:

2024-11-15 14:23:07 ERROR [auth] Login failed for user: farhan@example.com (IP: 192.168.1.42)

Pattern to extract timestamp, level, and email:

^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (\w+) .+ ([\w.+]+@[\w.]+)

The tester shows three capture groups:

  1. 2024-11-15 14:23:07
  2. ERROR
  3. farhan@example.com

Validating a slug

^[a-z0-9]+(?:-[a-z0-9]+)*$

Ensures a URL slug is lowercase alphanumeric with hyphens between words, no leading/trailing hyphens, no consecutive hyphens. Test input:

  • my-blog-post βœ…
  • My-Blog-Post ❌
  • -leading-hyphen ❌
  • double--hyphen ❌

Greedy vs. Lazy Matching

One of the most common regex bugs is the difference between greedy and lazy quantifiers.

Greedy (*, +, {n,}) β€” matches as much as possible.

Input: <b>Hello</b> and <b>World</b> Pattern: <b>.*</b>

A greedy .* matches everything from the first <b> to the last </b>: the entire string. Not what you wanted.

Lazy (*?, +?, {n,}?) β€” matches as little as possible.

Pattern: <b>.*?</b>

Now it matches <b>Hello</b> and <b>World</b> separately β€” two distinct matches. The tester makes this distinction immediately visible.


Flags Reference

Flag Effect
g (global) Find all matches, not just the first
i (case-insensitive) Match regardless of letter case
m (multiline) ^ and $ match line start/end, not string
s (dotall) . matches newline characters too
u (unicode) Enable full Unicode support

Tips for Writing Better Regex

Start simple and build up. Write the most specific literal match first, then generalise each part step by step. Trying to write the complete regex in one shot leads to bugs that are hard to isolate.

Use non-capturing groups (?:...) when you don't need the capture. Unnecessary capture groups add noise to the match results and slightly impact performance.

Anchor your patterns. \d+ matches digits anywhere in the string. ^\d+$ matches a string that is only digits. Omitting anchors is the second most common regex bug.

Test against both matching and non-matching cases. The pattern should match what you want β€” and not match things you don't want. Both directions matter.

Use named groups for clarity. (?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2}) is far more readable than (\d{4})-(\d{2})-(\d{2}) when you're extracting date components.


Frequently Asked Questions

Which regex flavour does the tester use? Most browser-based regex testers use JavaScript's built-in RegExp engine (ECMAScript). This is broadly compatible with regex in Python, Ruby, PHP, and Java, though there are some differences (Python uses (?P<name>) for named groups; JavaScript uses (?<name>)). Check which flavour your target language uses for edge cases.

What's the difference between .match() and .matchAll() in JavaScript? .match() with the global flag returns all matches but no capture group details. .matchAll() returns an iterator of all matches including capture groups. The regex tester typically mimics .matchAll() behaviour.

Why does my regex work in the tester but not in my code? Check the flags β€” the tester may have global or case-insensitive enabled that your code doesn't. Also check string delimiters in code β€” language-specific escaping may require double backslashes where the tester uses single.

How do I match a literal dot (.)? Escape it: \.. An unescaped . matches any character. 3.14 as a pattern matches "3X14", "3 14", etc. 3\.14 matches only the literal string "3.14".

Is the regex tester free? Yes β€” completely free, no sign-up required.


Regular expressions are one of those tools where the gap between "it almost works" and "it works correctly" is often a single character. The tester closes that gap by making the feedback loop immediate.

Try the Regex Tester free at sadiqbd.com β€” write patterns, test against real input, and see matches highlighted in real time.

Share:
Try the related tool:
Open Regex Tester

More Regex Tester articles