Regex Tester & Debugger

Test, debug, and build regular expressions with real-time pattern matching

Use this regex tester to build and debug regular expressions in real-time. See matches highlighted instantly, understand your pattern with our regex explainer, and visualize capture groups. 100% client-side — your data never leaves your browser.

Advertisement
/ /

Matches 0

Enter a pattern and test string to see matches

Capture Groups

Capture groups will appear here

Pattern Explanation

Enter a regex pattern to see its explanation

Quick Reference

Anchors

^Start of string/line
$End of string/line
\bWord boundary
\BNot word boundary

Quantifiers

*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n times
{n,m}Between n and m

Character Classes

.Any character
\dDigit [0-9]
\wWord char [a-zA-Z0-9_]
\sWhitespace
[abc]Any of a, b, or c
[^abc]Not a, b, or c

Groups & Lookaround

(abc)Capture group
(?:abc)Non-capturing group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
a|ba or b

Common Regex Patterns

Click any pattern to load it into the regex tester above. These patterns cover common validation and extraction use cases.

Pattern Description Category
^[a-zA-Z0-9._%+-]+@...Email addressValidation
^https?:\/\/...URLValidation
\b\d{3}[-.]?\d{3}...US Phone NumberExtraction
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)Validation
^(?=.*[a-z])(?=.*[A-Z])...Strong PasswordValidation
^\d{1,3}\.\d{1,3}...IPv4 AddressValidation
^#?([a-fA-F0-9]{6}...Hex Color CodeValidation
^[a-zA-Z0-9_-]{3,16}$UsernameValidation
^\d{5}(-\d{4})?$US ZIP CodeValidation
^\$?\d+(\.\d{2})?$Currency AmountValidation
<([a-z]+)[^>]*>...HTML Tag with ContentExtraction
\b[A-Z][a-z]+\bCapitalized WordsExtraction
^-?\d+(\.\d+)?$Integer or DecimalValidation
\s+Whitespace (1+)Utility
^[a-z0-9]+(?:-[a-z0-9]+)*$URL SlugValidation
(['\"])(.*?)\1Quoted StringExtraction
<!--[\s\S]*?-->HTML CommentExtraction
^\s*$Empty/Whitespace LineUtility
\b\w+\bAll WordsExtraction
(?<=@)\w+Domain from Email (lookbehind)Advanced
Advertisement

Regular Expression Guide

What is a Regular Expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Originally developed in theoretical computer science, regex is now a fundamental tool used across programming languages for text processing, validation, and data extraction.

Regular expressions are used everywhere: form validation in web applications, log file analysis, search-and-replace in text editors, data parsing in ETL pipelines, and URL routing in web frameworks.

Understanding Regex Syntax

Literal Characters

Most characters match themselves literally. The pattern hello matches the string "hello" exactly. However, certain characters have special meanings and must be escaped with a backslash to match literally.

Special Characters (Metacharacters)

These characters have special meanings in regex: . ^ $ * + ? { } [ ] \ | ( ). To match them literally, escape with a backslash: \. matches a period, \* matches an asterisk.

Character Classes

Square brackets define a character class that matches any single character within. [aeiou] matches any vowel. Ranges work too: [a-z] matches any lowercase letter, [0-9] matches any digit. Negate with ^: [^0-9] matches any non-digit.

Shorthand Character Classes

Common patterns have shortcuts: \d (digit), \w (word character: letters, digits, underscore), \s (whitespace). Uppercase versions negate: \D (non-digit), \W (non-word), \S (non-whitespace).

Quantifiers

Quantifiers specify how many times the preceding element should match:

  • * — Zero or more times (greedy)
  • + — One or more times (greedy)
  • ? — Zero or one time (optional)
  • {n} — Exactly n times
  • {n,} — n or more times
  • {n,m} — Between n and m times

Add ? after any quantifier to make it lazy (non-greedy): .*? matches as few characters as possible.

Groups and Capturing

Parentheses create groups that can be quantified together and capture their match for later use:

  • (abc) — Capturing group: matches "abc" and saves it
  • (?:abc) — Non-capturing group: groups without saving
  • (?<name>abc) — Named capture group
  • \1, \2 — Backreferences to captured groups
  • $1, $2 — References in replacement strings

Lookahead and Lookbehind

Lookaround assertions match a position without consuming characters:

  • (?=abc) — Positive lookahead: assert "abc" follows
  • (?!abc) — Negative lookahead: assert "abc" doesn't follow
  • (?<=abc) — Positive lookbehind: assert "abc" precedes
  • (?<!abc) — Negative lookbehind: assert "abc" doesn't precede

Example: \d+(?= dollars) matches digits only if followed by " dollars".

Regex Flags

Flags modify how the pattern is interpreted:

  • g (global) — Find all matches, not just the first
  • i (case-insensitive) — Ignore letter case when matching
  • m (multiline)^ and $ match line boundaries
  • s (dotAll) — Dot . matches newline characters too
  • u (unicode) — Enable full Unicode matching

Regex FAQ — Common Questions Answered

What is a regular expression (regex)?

A regular expression is a pattern that describes a set of strings. It's a powerful tool for searching, matching, and manipulating text. Regex is supported in virtually all programming languages and many text editors.

How do I test a regex pattern?

Enter your pattern in the input field above, then add your test string. Matches will be highlighted in real-time. Toggle the flags (g, i, m, s, u) to adjust matching behavior.

What do the regex flags mean?

g (global) finds all matches; i ignores case; m (multiline) makes ^ and $ match line boundaries; s (dotAll) makes . match newlines; u enables Unicode support.

What is a capture group?

Parentheses () create capture groups that save the matched text. You can reference captured text with $1, $2, etc. in replacements, or use backreferences \1, \2 within the same pattern.

How do I match a literal special character?

Escape special characters with a backslash. For example: \. matches a period, \* matches an asterisk, \\ matches a backslash, \( matches an opening parenthesis.

What is the difference between * and +?

* matches zero or more occurrences (including none), while + requires at least one occurrence. Pattern a* matches "", "a", "aa", but a+ requires at least one "a".

How do I match the start or end of a string?

Use ^ for the start and $ for the end. With the m (multiline) flag, these also match line boundaries within the string.

How do I make my regex case-insensitive?

Enable the i flag. This makes Hello match "hello", "HELLO", "HeLLo", etc. Click the "i" button in this tool to toggle it.

What is a non-greedy (lazy) match?

By default, quantifiers are greedy — they match as much as possible. Adding ? after a quantifier makes it lazy: .*? matches as few characters as possible.

What is a lookahead?

A lookahead checks if a pattern exists ahead without consuming characters. (?=pattern) is positive lookahead (pattern must follow), (?!pattern) is negative lookahead (pattern must not follow).

How do I validate an email with regex?

A common pattern is ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$. Note that perfect email validation is complex; for production use, consider additional validation or using your language's built-in validators.

Is my data safe using this tool?

Yes! This regex tester runs entirely in your browser. Your patterns and test strings are never sent to any server. Everything is processed client-side using JavaScript.

Advertisement