DEV Community

楊東霖
楊東霖

Posted on • Originally published at devplaybook.cc

Regex Tester Tool: Test and Debug Regular Expressions Online

Regex Tester Tool: Test and Debug Regular Expressions Online

Regular expressions are powerful but unforgiving. A misplaced . or missing escape changes everything. A good regex tester tool lets you see matches in real time, understand what your pattern is doing, and catch mistakes before they reach production.


Best Free Regex Tester Tool

DevPlaybook Regex Tester — test your regex against multiple strings simultaneously, see matches highlighted, and inspect capture groups.

Key features:

  • Live match highlighting as you type
  • Capture group visualization
  • Flag toggles (global, case-insensitive, multiline, dotAll)
  • Reference panel with common patterns
  • No account required

How to Test Regex Online

  1. Enter your pattern (without / delimiters)
  2. Set flags as needed (g for all matches, i for case-insensitive)
  3. Paste your test strings
  4. See matches highlighted in real time

Example: Testing an email pattern

Pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Flags: i (case-insensitive)

Test strings:
alice@example.com      ✓ match
not-an-email           ✗ no match
user@domain.co.uk      ✓ match
@nodomain.com          ✗ no match
Enter fullscreen mode Exit fullscreen mode

Regex Syntax Quick Reference

Character Classes

Pattern Matches
. Any character except newline
\d Digit (0-9)
\D Non-digit
\w Word character (a-z, A-Z, 0-9, _)
\W Non-word character
\s Whitespace (space, tab, newline)
\S Non-whitespace
[abc] Any of: a, b, c
[^abc] Not any of: a, b, c
[a-z] Range: a through z

Quantifiers

Pattern Meaning
* 0 or more
+ 1 or more
? 0 or 1 (optional)
{n} Exactly n times
{n,} n or more times
{n,m} Between n and m times
*? 0 or more (non-greedy)
+? 1 or more (non-greedy)

Anchors

Pattern Meaning
^ Start of string (or line with m flag)
$ End of string (or line with m flag)
\b Word boundary
\B Not a word boundary

Groups

Pattern Meaning
(abc) Capturing group
(?:abc) Non-capturing group
(?<name>abc) Named capturing group
(?=abc) Positive lookahead
(?!abc) Negative lookahead
(?<=abc) Positive lookbehind
(?<!abc) Negative lookbehind

Common Regex Patterns for Developers

Email Validation

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

Note: This is a reasonable practical check, not RFC 5322 compliant. The full spec is extraordinarily complex.

URL

https?://[^\s/$.?#].[^\s]*
Enter fullscreen mode Exit fullscreen mode

Or more precisely:

^(https?|ftp)://[^\s/$.?#].[^\s]*$
Enter fullscreen mode Exit fullscreen mode

IP Address (IPv4)

^(\d{1,3}\.){3}\d{1,3}$
Enter fullscreen mode Exit fullscreen mode

Strict version (validates 0-255 range):

^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$
Enter fullscreen mode Exit fullscreen mode

Phone Number (US)

^(\+1\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
Enter fullscreen mode Exit fullscreen mode

Date (YYYY-MM-DD)

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Enter fullscreen mode Exit fullscreen mode

UUID

^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
Enter fullscreen mode Exit fullscreen mode

Case-insensitive version:

^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
Enter fullscreen mode Exit fullscreen mode

Credit Card (basic format check)

^4[0-9]{12}(?:[0-9]{3})?$        # Visa
^5[1-5][0-9]{14}$                 # Mastercard
^3[47][0-9]{13}$                  # Amex
Enter fullscreen mode Exit fullscreen mode

HTML Tag Stripping

<[^>]*>
Enter fullscreen mode Exit fullscreen mode

Replace matches with empty string to remove tags. (For real HTML parsing, use a proper parser — regex has well-known limitations with nested structures.)

Hex Color

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Enter fullscreen mode Exit fullscreen mode

Semantic Version

^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
Enter fullscreen mode Exit fullscreen mode

Regex Flags Explained

Flags modify how the pattern matches:

Flag Code Effect
Global g Find all matches (not just first)
Case insensitive i [a-z] matches upper and lower case
Multiline m ^ and $ match line boundaries, not just string boundaries
Dot all s . matches newlines too
Unicode u Enable Unicode support, proper emoji/Unicode matching
// JavaScript
const re = /pattern/gi;  // global, case-insensitive

// Using RegExp constructor
const re2 = new RegExp('pattern', 'gi');
Enter fullscreen mode Exit fullscreen mode

Common Regex Mistakes

1. Not Escaping Special Characters

These characters have special meaning in regex: . * + ? ^ $ { } [ ] | ( ) \

To match them literally, escape with \:

Pattern to match "1.5":    1\.5   (not 1.5, which matches "1X5" too)
Pattern to match "(":      \(
Pattern to match "$":      \$
Enter fullscreen mode Exit fullscreen mode

2. Greedy vs Non-Greedy

Greedy quantifiers match as much as possible:

Pattern: <.+>
String:  <a>hello</a>
Match:   <a>hello</a>  (greedy: takes the whole thing)
Enter fullscreen mode Exit fullscreen mode

Non-greedy (? after quantifier) matches as little as possible:

Pattern: <.+?>
String:  <a>hello</a>
Matches: <a> and </a>  (non-greedy: stops at first >)
Enter fullscreen mode Exit fullscreen mode

3. ^ Inside Character Classes

^ at the start of a character class negates it:

[abc]   matches a, b, or c
[^abc]  matches anything EXCEPT a, b, or c
Enter fullscreen mode Exit fullscreen mode

Outside character classes, ^ anchors to start of string.

4. . Doesn't Match Newlines by Default

// Doesn't match across newlines
/start.+end/.test('start\nend')  // false

// Use dotAll flag to match newlines
/start.+end/s.test('start\nend')  // true

// Or use [\s\S] to match everything including newlines
/start[\s\S]+end/.test('start\nend')  // true
Enter fullscreen mode Exit fullscreen mode

5. Catastrophic Backtracking

Some patterns can cause exponential slowdown on certain inputs:

Dangerous pattern: (a+)+
Input: "aaaaaaaaaaaaaaaaab"
Result: engine tries exponentially many combinations before giving up
Enter fullscreen mode Exit fullscreen mode

Avoid nested quantifiers on overlapping character classes.


Regex in Different Languages

The core syntax is consistent, but details vary:

JavaScript:

const match = 'hello'.match(/h(e)llo/);
const replaced = 'hello world'.replace(/world/, 'there');
const found = /^\d+$/.test('123');
Enter fullscreen mode Exit fullscreen mode

Python:

import re
match = re.search(r'h(e)llo', 'hello')
replaced = re.sub(r'world', 'there', 'hello world')
found = bool(re.match(r'^\d+$', '123'))
Enter fullscreen mode Exit fullscreen mode

Go:

import "regexp"
re := regexp.MustCompile(`h(e)llo`)
match := re.FindString("hello")
Enter fullscreen mode Exit fullscreen mode

When Not to Use Regex

Regex is not always the right tool:

  • Parsing HTML/XML — use a proper DOM parser (BeautifulSoup, cheerio, etc.)
  • Validating emails "properly" — the full RFC spec is not practical to regex
  • Parsing deeply nested structures — use a parser generator or library
  • Lexing/parsing programming languages — regex can handle tokens but not grammar

Regex is best for: search, simple validation, transformation of well-defined string formats.


Practice

The best way to learn regex is to test real patterns against real data. Use DevPlaybook Regex Tester to experiment — it shows live matches, capture groups, and has a quick-reference panel built in.

Start with simple patterns, add complexity one piece at a time, and always test against edge cases (empty strings, Unicode characters, very long inputs).


Level Up Your Dev Workflow

Found this useful? Explore DevPlaybook — cheat sheets, tool comparisons, and hands-on guides for modern developers.

🛒 Get the DevToolkit Starter Kit on Gumroad — 40+ browser-based dev tools, source code + deployment guide included.

Top comments (0)