Regex Tester Online: Test Regular Expressions Instantly (Free 2026)

Test regular expressions with real time match highlighting, capture groups, and replace preview. 100% client side - no data leaves your browser.

Real-Time Matching Capture Groups Replace Preview Cheat Sheet

Regular Expression

/ /
Flags:

Test String

Matches will be highlighted here as you type...

Match Results

No matches yet. Enter a regex pattern and test string above.

Find & Replace

Use $1, $2, etc. for captured groups. Use $& for the full match.

Replace result will appear here...

Regex Cheat Sheet

Character Classes

.Any character (except newline)
\dDigit [0-9]
\DNon-digit
\wWord character [a-zA-Z0-9_]
\WNon-word character
\sWhitespace (space, tab, newline)
\SNon-whitespace
[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Range: a to z

Quantifiers

*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 (lazy)
+?1 or more (lazy)

Anchors & Boundaries

^Start of string / line
$End of string / line
\bWord boundary
\BNon-word boundary
(?=...)Positive lookahead
(?!...)Negative lookahead
(?<=...)Positive lookbehind
(?<!...)Negative lookbehind

Groups & References

(...)Capturing group
(?:...)Non-capturing group
(?<name>...)Named capturing group
\1Backreference to group 1
a|bAlternation (a or b)
$1Group 1 in replacement
$&Full match in replacement

About Regular Expressions

Regular expressions (regex or regexp) are powerful patterns used to match, search, and manipulate text. They are supported by virtually every programming language, text editor, and command-line tool. This free online regex tester lets you build and test patterns in real time with instant visual feedback.

What Are Regular Expressions?

A regular expression is a sequence of characters that defines a search pattern. Regex patterns can match literal text, character classes, repetitions, and complex structures like lookaheads and backreferences. They are essential for tasks like input validation, data extraction, log parsing, search-and-replace, and text processing.

Regex Flags Explained

Flags modify how the regex engine processes a pattern:

  • g (global) - Find all matches in the string, not just the first one.
  • i (case insensitive) - Match letters regardless of case.
  • m (multiline) - ^ and $ match the start and end of each line, not just the entire string.
  • s (dotall / single line) - The dot . matches newline characters as well.
  • u (unicode) - Enables full Unicode matching, treating surrogate pairs as single characters.

Common Regex Use Cases

  • Email validation: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • URL matching: https?:\/\/[^\s/$.?#].[^\s]*
  • IP address detection: \b(?:\d{1,3}\.){3}\d{1,3}\b
  • Date parsing: \d{4}-\d{2}-\d{2}
  • HTML tag matching: <([a-zA-Z]+)\b[^>]*>.*?<\/\1>

Tips for Writing Regex

  • Start simple and build up complexity gradually. Test each part before combining.
  • Use non-capturing groups (?:...) when you don't need the captured value.
  • Prefer lazy quantifiers (*?, +?) when matching content between delimiters.
  • Anchor your patterns with ^ and $ when validating entire strings.
  • Escape special characters (. * + ? ^ $ { } [ ] ( ) | \) with a backslash when matching them literally.
  • Be cautious with .* - it is greedy by default and may match more than intended.

JavaScript Regex Engine

This tool uses the JavaScript regex engine (RegExp), which supports ECMAScript 2018+ features including named capture groups, lookbehinds, and the s (dotall) flag. The behavior may differ slightly from PCRE (PHP/Python) or POSIX regex engines. All processing happens entirely in your browser - your test data is never sent to any server.

Ready-to-Use Regex Patterns

Copy these patterns and test them above:

  • Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • Phone (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
  • URL: https?:\/\/[^\s/$.?#].[^\s]*
  • IPv4: \b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b
  • Date (YYYY-MM-DD): \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])
  • Hex color: #([0-9a-fA-F]{3}){1,2}\b
  • Password strength: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
  • Remove HTML tags: <[^>]*>
  • Trailing whitespace: \s+$ (with multiline flag)

Frequently Asked Questions

How do I test a regex expression online?
Enter your pattern in the "Regex Pattern" field above, then type or paste test text in the "Test String" field. Matches are highlighted in real time. Enable the g flag to find all matches.

What regex matches an email address?
A practical email regex is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. Note that fully RFC-5322 compliant email validation is extremely complex - for most applications, this simpler pattern is sufficient. For production validation, also verify with a confirmation email.

Why does my regex work in Python but not JavaScript?
JavaScript's regex engine differs from Python's (PCRE). Key differences: JS does not support atomic groups, possessive quantifiers, or \A/\Z anchors. Use ^/$ with the m flag instead. Named groups use (?<name>...) syntax in both, but backreferences differ (\k<name> in JS vs (?P=name) in Python).

How do I match but not capture a group?
Use non-capturing groups: (?:pattern) instead of (pattern). This groups the pattern for quantifiers or alternation without creating a capture group, which is faster and keeps your match results cleaner.

Related Tools & Articles