Ttooleras
🎯

Regex Tester

Generators

Test and debug regular expressions with live matching and explanation. Free, private — all processing in your browser.

//
Presets:
Advertisement

The Regex Tester is a free online tool to build, test, and debug regular expressions with live matching, syntax highlighting, and detailed explanations of what each part of your pattern does. Paste any text and any regex pattern — matches are highlighted instantly, capture groups are extracted, and the tool explains in plain English what your pattern means. Supports the JavaScript regex engine natively (same as RegExp in Node.js and browsers) with compatibility notes for PCRE (PHP, Perl), Python re, Go regexp, and .NET Regex.

Regular expressions are the Swiss Army knife of text processing: validate email addresses, extract URLs from documents, parse log files, rewrite strings, search code, and transform data. But they are notoriously hard to read and easy to get wrong. This regex tester shortens the feedback loop — instead of writing a regex, running your code, seeing it fail, and editing blindly, you iterate in real time, see exactly what matches, inspect capture groups, and understand the pattern. It runs entirely in your browser — your patterns and test strings never leave your device.

Regex Tester — key features

Live regex matching

See matches highlighted in real-time as you edit the pattern or the test string. No need to click a button. Matches update instantly.

Capture group inspection

Each numbered and named capture group is shown separately, with its content and position. Essential for extracting structured data from text.

Plain-English explanation

The tool explains what each part of your regex does (\d means any digit, + means one or more, etc.). Great for learning regex or reading someone else's pattern.

All JavaScript flags supported

Toggle g (global), i (case-insensitive), m (multiline), s (dotall), u (unicode), y (sticky) and see how each changes the result.

Replace mode

Test find-and-replace operations. Use $1, $2 etc. for capture group references in the replacement string.

Common pattern library

Built-in patterns for email, URL, IP address, phone, credit card, date, hex color, and more. Click to insert and customize.

Error detection

Invalid regex syntax is reported with a clear error message and position. No more silent failures.

Multi-language cheat sheet

Syntax differences between JavaScript, Python re, PHP PCRE, Go regexp, and .NET Regex are noted in the reference panel.

How to use the Regex Tester

  1. 1

    Paste your test string

    Drop the text you want to match against — API responses, log lines, user input, or file contents. The tester handles strings up to megabytes in size.

  2. 2

    Write or paste your regex pattern

    Enter the regex pattern in the pattern field. Leading and trailing slashes are optional — the tester handles both forms.

  3. 3

    Set flags

    Toggle the g, i, m, s, u, y flags depending on what you need. Hover each flag for a description.

  4. 4

    Read the matches

    Matches are highlighted in the test string. The sidebar shows each match's position, captured text, and named/numbered groups.

  5. 5

    Use the explanation panel

    Click any part of the pattern to see what it does. Great for debugging complex regex or learning regex as you go.

  6. 6

    Test replacement (optional)

    Switch to Replace mode to see how your regex transforms the text. Use $1, $2, $<name> to reference capture groups in the replacement string.

Common use cases for the Regex Tester

Input validation

  • Validate email addresses: Check email format before submitting forms. Use a simple pattern like `^[^\s@]+@[^\s@]+\.[^\s@]+$` for most cases — not perfect RFC 5322 compliance, but 99.9% accurate for real emails.
  • Validate URLs: Accept http/https URLs with optional paths and query strings. `^https?:\/\/[^\s]+$` is a good starting point.
  • Validate phone numbers: Country-specific formats like US `^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$` or more permissive international formats.
  • Validate passwords: Enforce complexity rules: `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$` for lowercase, uppercase, digit, and min 8 chars.
  • Validate UUIDs, credit cards, dates: Every common data format has a standard regex. Validate before processing to reject malformed input early.

Text extraction

  • Extract emails from text: Scan documents, logs, or CSV files and pull out every email address with `[\w.+-]+@[\w-]+\.[\w.-]+`.
  • Extract URLs from HTML: Find all href links with `href="([^"]+)"` capturing the URL in group 1.
  • Extract log timestamps: Parse log lines like `2026-05-05T14:23:01Z ERROR ...` with `^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)`.
  • Extract IP addresses: Find IPv4 addresses with `\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b` or IPv6 with a more complex pattern.

Search and replace

  • Rename variables across a codebase: Find `\bgetUserName\b` and replace with `getUsername` while respecting word boundaries to avoid matching substrings.
  • Clean up formatting: Collapse multiple spaces with `\s+` → single space. Remove trailing whitespace with `\s+$` in multiline mode.
  • Normalize quotes and dashes: Convert smart quotes `[“”]` to straight `"`, em-dashes `—` to double-hyphens `--`, etc.
  • Strip HTML tags: `<[^>]+>` removes simple HTML tags. For real-world HTML, use an HTML parser — regex for HTML is a well-known foot-gun.

Log parsing and analysis

  • Parse Apache/Nginx access logs: Extract IP, timestamp, request method, URL, and status code from structured log lines.
  • Extract error stack traces: Find all error messages and their file/line references in application logs.
  • Count and categorize events: Match log patterns by severity, component, or event type to build summaries.

Regex Tester — examples

Email validation

Simple but effective email regex. Matches virtually all real email addresses.

Input
Pattern: ^[^\s@]+@[^\s@]+\.[^\s@]+$
Test: alice@example.com
Output
✓ Match
Group 0: alice@example.com

Extract all URLs

Global flag finds all matches, not just the first.

Input
Pattern: https?:\/\/[^\s]+  (flags: g)
Test: Visit https://tooleras.com and https://github.com for info
Output
Match 1: https://tooleras.com
Match 2: https://github.com

Capture groups

Parentheses capture portions of the match into groups.

Input
Pattern: (\w+)@(\w+\.\w+)
Test: contact@tooleras.com
Output
Group 0: contact@tooleras.com
Group 1: contact
Group 2: tooleras.com

Find and replace with backreference

Swap order using $1, $2 in replacement.

Input
Pattern: (\w+)\s+(\w+)
Replace: $2 $1
Test: John Doe
Output
Doe John

Named groups (ES2018+)

Name your groups for clarity in larger patterns.

Input
Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Test: 2026-05-05
Output
year: 2026
month: 05
day: 05

Lookahead (non-consuming)

Match only if followed by a pattern, without including it.

Input
Pattern: \d+(?= dollars)
Test: 50 dollars and 30 euros
Output
Match: 50  (30 skipped because not followed by "dollars")

Case-insensitive search

The i flag matches any case.

Input
Pattern: hello  (flags: gi)
Test: Hello HELLO hello HeLLo
Output
4 matches (case ignored)

Technical details

A regular expression (regex, regexp) is a pattern that describes a set of strings. Regex engines scan a target string and find all positions where the pattern matches. Every programming language ships with a regex engine — they share a common core of syntax but differ in advanced features (lookbehind, named groups, recursion).

This tester uses the JavaScript regex engine — the same engine that runs in browsers and Node.js. JavaScript regex is based on ECMAScript (specifically ES2018 added lookbehind, named groups, and Unicode property escapes). For patterns that need features from other flavors (like PCRE recursion or .NET balancing groups), use a flavor-specific tester in that language.

Regex core syntax (works everywhere):

``
Literal characters a, b, 1, @ matches those characters
Dot . matches any character except newline
Character class [abc] [a-z] [^0-9] matches any (or none) listed
Anchors ^ $ \b \B start, end, word boundary, non-boundary
Quantifiers ? * + {n} {n,m} 0-1, 0+, 1+, exactly n, n-to-m
Alternation cat|dog matches cat or dog
Groups (abc) captures 'abc'
Non-capturing group (?:abc) groups without capturing
Backreferences \1 \2 refer to earlier capture
Escape special \. \* \? match literal . * ? etc.
``

Flags (modifiers):

``
g global — find all matches (not just first)
i case-insensitive
m multiline — ^ and $ match line starts/ends, not just string start/end
s dotall — . matches newline too
u unicode — treat pattern as Unicode code points
y sticky — match from lastIndex only
``

Advanced features (ES2018+):

``
Lookahead (?=x) — position followed by x
Negative ahead (?!x) — position NOT followed by x
Lookbehind (?<=x) — position preceded by x
Negative behind (?<!x) — position NOT preceded by x
Named groups (?<name>x) — reference later with \k<name>
Unicode prop \p{Letter} — match any Unicode letter (requires u flag)
``

Performance notes: Some patterns can cause catastrophic backtracking — exponential runtime on certain inputs. Classic example: (a+)+$ applied to aaaaaaaaaaX. Avoid nested quantifiers and overlapping alternation. Modern engines (V8, Rust regex) have linear-time matchers that refuse such patterns or handle them safely.

Common problems and solutions

Catastrophic backtracking

Patterns like `(a+)+$` on `aaaaX` can take exponential time. Avoid nested quantifiers and overlapping alternation. Use possessive quantifiers or atomic groups in engines that support them (not JavaScript). Test with worst-case input before deploying regex to production.

Forgetting the global flag

Without the `g` flag, only the first match is returned even if there are many. Add `g` to find all matches. The `g` flag also affects `replace` behavior — without it, only the first match is replaced.

Parsing HTML with regex

HTML is not a regular language — nested tags, attributes with quoted values, optional elements, all defeat regex. For anything beyond simple tag matching, use an HTML parser (cheerio, DOMParser, BeautifulSoup). Jeff Friedl and Stack Overflow agree: regex for HTML is forbidden.

Unescaped special characters

Characters like `.`, `*`, `+`, `?`, `(`, `)`, `[`, `]`, `{`, `}`, `\`, `|`, `^`, `$` have special meaning. To match them literally, escape with backslash: `\.` matches a dot. `\(` matches a literal parenthesis.

Anchors not working with multiline text

`^` and `$` match the start/end of the **entire string** by default. To match line starts/ends, enable the `m` (multiline) flag. Common mistake when processing log files.

Dot does not match newlines by default

The `.` character matches any character except newline. To include newlines (for multi-line patterns), enable the `s` (dotall) flag.

Greedy vs lazy quantifiers

`.*` is greedy — matches as much as possible. `.*?` is lazy — matches as little as possible. Use lazy quantifiers when you want `<.*?>` to match one tag instead of everything from the first `<` to the last `>`.

Using regex for email validation aiming at RFC perfection

The full RFC 5322 email regex is thousands of characters and still incomplete. Use a simple pattern (`^[^@]+@[^@]+\.[^@]+$`) plus actual verification (send a confirmation email). Do not over-engineer — the simpler regex catches 99.9% of user typos.

Regex Tester — comparisons and alternatives

JavaScript regex vs PCRE (PHP, Perl): JavaScript lacks some PCRE features like recursion, possessive quantifiers, atomic groups, (?P<name>...) syntax (though modern JS uses (?<name>...)), and conditional patterns (?(1)yes|no). JavaScript is simpler but sufficient for 99% of use cases.

JavaScript regex vs Python re: Very similar. Python uses (?P<name>...) for named groups (JavaScript uses (?<name>...) since ES2018). Python has re.VERBOSE mode allowing whitespace and comments in the pattern, which JavaScript lacks. Both support lookahead and lookbehind.

JavaScript regex vs Go regexp: Go uses RE2, which guarantees linear time (no catastrophic backtracking). But Go does not support lookahead, lookbehind, or backreferences — features that cannot be implemented in linear time. Go's regex is safer but less powerful.

JavaScript regex vs .NET Regex: .NET supports balancing groups (for matching nested constructs), more built-in character classes, and named groups with (?<name>...). Otherwise similar to JavaScript.

JavaScript regex vs grep: BSD grep uses basic POSIX regex (limited — no ?, +, | without -E). GNU grep with -E (extended) or -P (PCRE) gives you modern features. Ripgrep uses Rust's regex crate, similar to Go RE2 — linear time, no lookbehind.

Regex vs string methods: For simple operations (startsWith, endsWith, includes, split by fixed string), string methods are faster and more readable. Use regex when you need pattern matching — variable content, multiple alternatives, or capture groups.

Frequently asked questions about the Regex Tester

What is a regex and why should I learn it?

A regular expression (regex) is a pattern that describes text. It lets you search, validate, extract, and transform strings with a short, expressive syntax. Regex is universal — used in every programming language, every text editor, every search tool. Learning regex makes you dramatically more productive at text processing, log analysis, data cleaning, and input validation.

How do I test a regex online?

Paste your regex pattern into the Pattern field, paste your test string into the Test String field, and turn on the flags you need (g for global, i for case-insensitive, m for multiline). Matches appear highlighted in the test string instantly. The Explanation panel shows what each part of the pattern does.

Which regex flavor does this tester use?

JavaScript — the regex engine built into browsers and Node.js. Most regex syntax is universal, but some advanced features differ between flavors. If you are writing a regex for Python, PHP, Go, or .NET, the core will work the same but check the flavor-specific notes for lookbehind, named groups, and conditional patterns.

How do I match a literal special character?

Escape it with a backslash. \. matches a literal dot (instead of any character), \( matches a literal parenthesis, \\ matches a literal backslash. The full list of characters that need escaping in JavaScript regex: . * + ? ^ $ ( ) [ ] { } | \.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers (*, +, ?, {n,m}) match as much as possible. Lazy (non-greedy) quantifiers add a ?: *?, +?, ??, {n,m}? — match as little as possible. Example: <.*> on <a><b> matches the entire <a><b> (greedy). <.*?> matches just <a> (lazy).

What are capture groups?

A capture group is a parenthesized part of the pattern whose matched content is captured for later reference. (\d+)-(\d+) on 123-456 captures 123 in group 1 and 456 in group 2. Access groups in JavaScript via match[1], match[2]. Use (?:...) for a non-capturing group when you need the grouping but not the capture.

What are lookahead and lookbehind?

Zero-width assertions that match a position without consuming characters. (?=x) — position followed by x (positive lookahead). (?!x) — not followed by x. (?<=x) — preceded by x (positive lookbehind). (?<!x) — not preceded by x. Useful for context-sensitive matching: \d+(?= USD) matches digits only if followed by USD.

How do I use capture groups in replace?

In JavaScript, reference captures with $1, $2 in the replacement string. For named groups, use $<name>. Example: str.replace(/(\w+) (\w+)/, '$2 $1') swaps two words. Most other languages use similar syntax (PHP, Python, Perl, .NET).

What are the common regex flags?

g (global) — find all matches, not just the first. i (case-insensitive) — match letters regardless of case. m (multiline) — ^ and $ match line boundaries. s (dotall) — . matches newlines too. u (unicode) — treat pattern as Unicode code points (enables \p{...}). y (sticky) — match from lastIndex. Combine flags as needed: /pattern/gim.

Why is my regex slow or crashing the browser?

Catastrophic backtracking. Patterns like (a+)+$ on long input take exponential time because the engine tries every possible way to match. Fix: avoid nested quantifiers, avoid overlapping alternation, use atomic groups (not in JavaScript) or restructure the pattern. Modern engines like V8 have some protection but cannot save all patterns.

Additional resources

Advertisement

Related tools

All Generators

Learn more

Explore more tools

200+ free tools that run in your browser.

Browse all tools →