Regex Tester

Test regular expressions in real-time and see matching results. Supports pattern matching, group capture, and string replacement.

/ /
g

g: Global match, i: Case insensitive, m: Multiline, s: Dotall (. matches newlines), u: Unicode

Match Results

0 matches

No matches found.

Replace matched patterns with another string.

Common Patterns

Regex Cheat Sheet

Character Classes

. - Any character (except newline)
\d - Digit [0-9]
\D - Non-digit
\w - Word character [a-zA-Z0-9_]
\W - Non-word character
\s - Whitespace
\S - Non-whitespace

Anchors

^ - Start of string/line
$ - End of string/line
\b - Word boundary
\B - Non-word boundary

Quantifiers

* - 0 or more
+ - 1 or more
? - 0 or 1
{n} - Exactly n
{n,} - n or more
{n,m} - Between n and m

Groups

(abc) - Capture group
(?:abc) - Non-capture group
(?<name>abc) - Named group
\1 - Backreference

Lookaround

(?=abc) - Positive lookahead
(?!abc) - Negative lookahead
(?<=abc) - Positive lookbehind
(?<!abc) - Negative lookbehind

Special Characters

[abc] - Character set
[^abc] - Negated set
[a-z] - Character range
a|b - Alternation (OR)
\ - Escape character

Quick Tips

Regular expressions are powerful but notoriously tricky to get right. Testing patterns against real data before using them in code saves hours of debugging.

You Might Also Like

Worth Reading

What is Regex Tester?

Regex Tester is an online tool for creating, testing, and debugging regular expressions in real time. Regular expressions are powerful pattern-matching strings used throughout programming for text search, data validation, and string manipulation. This tool highlights matches instantly as you type, displays capture groups, and includes built-in pattern templates for common formats like email addresses, phone numbers, and URLs.

User Guide

  1. Enter your regular expression in the Pattern field (without surrounding slashes).
  2. Select the flags you need: g (global search), i (case-insensitive), m (multiline), and others.
  3. Type or paste the text you want to test in the Test String area.
  4. Matches are highlighted in real time, and match count and capture groups are displayed below.
  5. Enable Replace Mode to test replacing matched text with a substitution string.
  6. Click any pattern from the template list to apply it instantly.

Core Features

  • Real-time matching: Matches are highlighted in the test string the moment you type a pattern.
  • Flag selection: Apply g (global), i (case-insensitive), m (multiline), s (dotall), and u (unicode) flags individually.
  • Capture group display: View the content captured by parenthesized groups in a separate results panel.
  • Replace mode: Test string replacements using captured group references ($1, $2, etc.).
  • Pattern templates: Apply commonly used patterns for email, URL, IP address, and more with one click.
  • Syntax cheat sheet: Quickly reference regex syntax and special character meanings right on the page.

When This Comes in Handy

  • Form validation: Test patterns that validate email addresses, phone numbers, postal codes, and other user inputs.
  • Log analysis: Extract error messages, IP addresses, and timestamps from server log files using patterns.
  • Data cleaning: Remove unwanted characters or standardize formats in CSV or text datasets.
  • Code refactoring: Find and replace variable names, function calls, or patterns across source code files.
  • Web scraping: Extract specific data from HTML or JSON responses using pattern matching.

Pattern Recipes to Try Right Now

Reformat dates with capture groups. Paste a few lines containing dates like 2026-07-02 into the test string, set the pattern to (\d{4})-(\d{2})-(\d{2}), enable Replace Mode, and use $2/$3/$1 as the replacement. The result panel shows 07/02/2026 instantly — a safe dry run before you apply the same find-and-replace in your editor across hundreds of files.

See greedy vs lazy with your own eyes. Test the string <b>bold</b> and <i>italic</i> against <.+>: the highlight swallows everything from the first < to the last >. Now add a question mark — <.+?> — and each tag is matched separately. No written explanation of quantifier greediness beats watching the highlight change.

Pull structured data out of a log line. Given 2026-07-02 14:03:11 ERROR db timeout after 3000ms, the pattern ^(\S+ \S+) (\w+) (.+)$ with the m flag captures the timestamp in $1, the level in $2, and the message in $3 for every line at once. This is the fastest way to prototype an extraction rule before writing the actual parsing code.

Moving a Tested Pattern into Code

Once a pattern works here, port it carefully — the most common breakage is escaping. In a JavaScript regex literal you can copy it verbatim: /(\d{4})-(\d{2})/g. But if you build the regex from a string, every backslash must be doubled: new RegExp("(\\d{4})-(\\d{2})", "g"). Python avoids the same trap with raw strings (re.compile(r"(\d{4})-(\d{2})")), and Java requires doubled backslashes inside string literals as well. Also remember that flags travel separately: the g flag has no direct equivalent in Python or Java, where "find all" behavior comes from the function you call (re.findall, Matcher.find() in a loop) rather than from the pattern itself.

Common Questions

Q: What happens without the g flag?

Without the g (global) flag, only the first match is found and the search stops. Enable the g flag to find all matches in the entire test string.

Q: How do I use capture groups ($1, $2)?

Parentheses () create capture groups. In replacement strings, use $1 for the first group, $2 for the second, and so on. For example, in the pattern (\w+)@(\w+), $1 refers to the part before @ and $2 to the part after.

Q: How do I search for special characters literally?

Characters with special meaning in regex (. * + ? ^ $ [ ] { } ( ) | \) must be preceded by a backslash to be treated as literals. For example, use \. to search for an actual period.

Q: What is the difference between greedy and lazy matching?

Greedy matching (.*) captures as much text as possible, while lazy matching (.*?) captures as little as possible. Use lazy matching when you need the shortest match, such as extracting content between HTML tags.

Q: When should I use non-capturing groups (?:...)?

Use them when you need grouping for alternation or repetition but do not need to capture the matched text. For example, (?:http|https):// groups the protocol without affecting the numbering of $1, $2, etc.

Q: Why does my regex run very slowly?

Nested repetition patterns like (a+)+b can cause catastrophic backtracking, where the engine tries exponentially many paths. Simplify the pattern or use atomic groups and possessive quantifiers where supported.

Q: Do regular expressions differ between programming languages?

The core syntax is largely the same, but advanced features like lookbehind, lookahead, and Unicode handling vary between languages. This tool uses the JavaScript regex engine, which covers most common use cases.

Q: Is my data sent to an external server?

No. All regex testing is performed locally in your browser. Neither your patterns nor your test strings are transmitted anywhere, so you can safely test with sensitive data.