Regex Tester — Test Regular Expressions Online

Write, test, and debug regular expressions against sample text. Every match shows position and captured groups — all in your browser.

Test & DebugMatch HighlightingCapture Groups6 FlagsInstant Results

Regular expressions are powerful but notoriously hard to debug. You write a pattern, run it against text, and get nothing — or worse, it matches everything — and you do not know why. Stack Overflow answers give you patterns that work on demo data but fail on real input with edge cases you never considered.

This tool gives you instant, transparent feedback for every regex you write. Type a pattern, toggle flags, paste your test text, and see each match with its exact position and captured groups. No more guessing whether the g flag is set or whether .* is eating too much — the results show you exactly what the engine sees.

All testing runs entirely in your browser using the native JavaScript RegExp engine. Your pattern and test data are never transmitted over the network by this tool. This also means the regex behavior you see here is exactly what you will get in your JavaScript code — same engine, same results.

.*

Try it now

Write a pattern, set flags, paste text, and test

//
Load example:

Enter text to search with your pattern

0 chars

Use JavaScript replacement syntax such as $& for the whole match and $1 for the first capture group.

Replacement output
Run a pattern against text to preview replacement output.

Quick example — see what this tool does

InputPattern + text you want to test
/[\w.-]+@[\w.-]+\.\w+/gi
Text: Contact ana@example.com or support@site.cn
Output2 matches with positions
[1] "ana@example.com" at index 8
[2] "support@site.cn" at index 26

Common regex mistakes (and how to fix them)

Click any example to load it into the tool and see the issue for yourself.

Understanding JavaScript regex

The JavaScript RegExp engine: what it supports

JavaScript's built-in regex engine follows the ECMAScript specification. It supports most common regex features but lacks some advanced capabilities found in PCRE, Perl, or .NET:

FeatureJS SupportNotes
Character classes, quantifiers, alternationFullAll basic regex features work as expected.
Capture groups (named and numbered)FullNamed groups with (?<name>...) since ES2018.
Lookahead (positive and negative)Full(?=...) and (?!...) always supported.
LookbehindES2018+Not in IE or old Safari. Use capture groups for broad compatibility.
Unicode property escapesES2018+\p{Letter} requires the u flag. Use instead of \w for non-ASCII text.
Atomic groups, possessive quantifiersNoneNot in ECMAScript. No equivalent workaround in pure regex.
Recursive patterns, subroutinesNoneCannot match nested structures like balanced parentheses with pure regex.

Real-world use cases

Validating form input

Test email patterns, phone numbers, postal codes, or any formatted input against sample data before adding the regex to your validation code. Catch edge cases — like a pattern that accidentally accepts invalid formats — before they reach production.

Extracting data from logs

Write a pattern to pull timestamps, error codes, IP addresses, or user IDs out of log lines. Test it against real log samples to confirm it captures all variants (single-digit days, IPv6 addresses, port numbers).

Cleaning and transforming text

Build find-and-replace patterns for data cleanup: strip HTML tags, normalize whitespace, reformat dates, or extract values from semi-structured text. Test the pattern before running it across thousands of lines.

Learning regex syntax

If you are learning regular expressions, experiment here instead of your codebase. Toggle flags, test edge cases, and see exactly what each metacharacter matches — feedback is instant and you cannot break anything.

Debugging a failing pattern

When a regex works on one input but silently fails on another, paste both inputs here and compare the match results side by side. The position index and captured groups often reveal the mismatch immediately.

Writing URL rewrite rules

Mod_rewrite, nginx, and CDN rules use regex for URL matching. Test your pattern against real URL examples — including encoded characters, query strings, and trailing slashes — before deploying the rule.

The s (dotAll) flag: matching newlines with dot

By default, the . metacharacter matches any single character except line terminators (\n, \r, etc.). The s flag (added in ES2018) changes this so . also matches line terminators. This is useful when you want a pattern to span multiple lines. Older JavaScript engines may throw an invalid flag error for s — check your target environment before relying on it.

When not to use a browser regex tester

  • Untrusted user-supplied patterns: If your application lets users enter regex patterns (e.g., a search filter), never test those patterns in this tool without review. For untrusted user-supplied patterns, consider a timeout, sandbox, or a non-backtracking engine such as RE2.
  • Parsing HTML or XML: Regex cannot correctly parse nested markup. Use a DOM parser (DOMParser, cheerio, jsdom) instead. You cannot parse arbitrary HTML with a regular expression.
  • Production validation: Client-side regex testing is useful for development but should not be the only validation layer. Always validate on the server side too — client-side checks can be bypassed.
  • Patterns with secrets: Never paste regex patterns that contain API keys, authentication tokens, or internal URL structures into any browser tool. Browser extensions and clipboard managers can read textarea content.

Security and privacy

Regex testing runs entirely in your browser using the native RegExp engine. Your pattern and test text are never transmitted by this tool. However, never paste sensitive material into any online tool — this includes API keys, authentication tokens, production data, or personally identifiable information. Browser extensions, clipboard managers, and device-level software can read textarea content. For patterns that involve internal system details, test offline with a local REPL.

Frequently asked questions

What is the difference between String.match(), String.matchAll(), and RegExp.exec()?

`String.match()` with the `g` flag returns an array of all full matches (no capture groups or positions). Without `g`, it returns the first match with capture groups. `String.matchAll()` returns an iterator of all matches, each with the full match, capture groups, index, and input — it requires the `g` flag or throws TypeError. `RegExp.exec()` returns one match at a time with full detail; call it repeatedly with a sticky or global regex to step through matches. For debugging, `matchAll()` is usually the most informative because it gives positions and groups for every match at once.

Why does my regex work on another tester but not in JavaScript?

Different regex engines support different features. JavaScript's RegExp engine (ECMAScript) does NOT support: atomic groups `(?>...)`, possessive quantifiers `++` `*+` `?+`, recursive patterns, conditionals `(?(cond)yes|no)`, or `\Q...\E` quoting. If your pattern uses PCRE, Perl, or .NET features, it will fail in JavaScript. Always select the 'ECMAScript' or 'JavaScript' flavor when using online regex testers.

What does each regex flag do in JavaScript?

`g` — global: find all matches, not just the first. `i` — case-insensitive: `/[a-z]/i` matches A-Z too. `m` — multiline: `^` and `$` match start/end of each line, not just the whole string. `s` — dotAll (ES2018): `.` matches newline characters too. Older JavaScript engines may throw an invalid flag error for `s`. `u` — unicode: enables Unicode property escapes and correct surrogate pair handling. `v` — unicodeSets (ES2024): extended Unicode mode with set operations and string literals in character classes.

How do I match a literal dot, asterisk, or question mark?

Prefix the character with a backslash to escape it: `\.` matches a literal period, `\*` matches an asterisk, `\?` matches a question mark. In a JavaScript string, the backslash itself must be escaped in the string literal — so `new RegExp('\\.')` or the literal `/\./`. The 12 characters with special meaning in regex are: `. * + ? [ ] ( ) { } ^ $ |` and the backslash `\`.

Why is my regex freezing the browser tab?

This is almost always catastrophic backtracking — nested quantifiers like `(a+)+b` or `(.+)+c` that create exponentially many ways to partition the input. When the pattern fails to match, the engine tries every combination before giving up. To fix: remove the nesting (usually `a+b` works the same). For untrusted user-supplied patterns, consider a timeout, sandbox, or a non-backtracking engine such as RE2. This tool runs in your browser's JavaScript engine, so complex patterns can still freeze the tab.

Can I use lookbehind in all browsers?

No. Lookbehind (`(?<=...)` and `(?<!...)`) was added in ES2018. It is supported in all modern browsers (Chrome 62+, Firefox 78+, Safari 16.4+) but not in Internet Explorer or very old mobile WebViews. If your audience includes users on older devices, avoid lookbehind and use capture groups instead. Node.js has supported lookbehind since version 10.

Is my test text uploaded to a server?

No. All regex testing runs entirely in your browser using the native `RegExp` engine. Your pattern and test text are never transmitted by this tool. The page may load analytics or advertising scripts that send page-view data, but your input content stays on your machine. Never paste sensitive data such as API keys, user PII, or production tokens into any browser-based tool.

Related tools you might need

Tool guide

About Regex Tester

A regex tester helps you iterate on regular expressions against sample text before adding them to production code. It is useful for parsing logs, validating formats, extracting IDs, and understanding how flags affect matches.

Start with small sample inputs, test edge cases, and avoid overly broad patterns when user input or large text files are involved.

Privacy note

Most FreeToolsBox tools run directly in your browser for processing. Some pages may still load analytics, ads, or third-party services. Avoid entering passwords, private keys, production tokens, personal IDs, or other sensitive data.

Validation-grade guide

How to use Regex Tester well

Core validation tool

Best for

Test a regular expression against sample text before using it in code or data cleanup.

Shows matches and errors quickly, helping users tune flags and patterns before applying them elsewhere.

Example workflow

  1. Input: Pattern: #[A-Z]-\d+; Text: Order #A-1001 and #B-2002
  2. Action: Run the regex with the global flag enabled.
  3. Expected result: Both order IDs are matched and can be reviewed before copying the pattern.

Quality checks

  • Reports invalid patterns clearly.
  • Makes flags and sample text part of the tested state.
  • Works well for extraction, validation, and cleanup examples.

Watch out for

  • Catastrophic backtracking can make complex patterns slow.
  • Regex syntax differs between JavaScript, Python, PCRE, and databases.
  • Global and multiline flags can change results significantly.

Do not use it for

  • Parsing complex HTML, programming languages, or nested formats.
  • Validating security-sensitive input without server-side checks.

What to measure in the 90-day validation

  • tool_used:test
  • tool_error rate
  • tool_copied
  • input length bucket

Testing uses the browser's JavaScript RegExp engine; results may differ from other regex engines.

Learn the concept

Regex greedy vs lazy

A practical JavaScript regex guide to greedy and lazy quantifiers, capture groups, replacement previews, and safer matching against real sample text.

Read the guide →

Common use cases

  • Test a pattern before using it in JavaScript.
  • Extract IDs, emails, URLs, or log fields from text.
  • Compare behavior with global or case-insensitive flags.
  • Debug why a pattern matches too much or too little.

Examples

  • Test an order ID pattern against sample log lines before using it in a script.
  • Try case-insensitive and multiline flags to see how match results change.
  • Paste a small sample of messy text and verify that only the intended email addresses, IDs, or tags match.

Practical tips

  • Start with a small sample and expand the pattern only after the expected matches are clear.
  • Keep patterns engine-specific; JavaScript regex behavior may differ from PCRE, Python, or database engines.
  • Avoid overly broad patterns before applying regex replacement to production data.

Frequently asked questions

What is a regex flag?

A flag changes matching behavior, such as global matching, case-insensitive matching, or multiline anchors.

Why does my regex match more than expected?

Greedy quantifiers and missing anchors are common causes. Try narrowing the pattern or using non-greedy quantifiers.

Can regex validate every format perfectly?

Regex is useful for many formats, but complex grammars such as full HTML or programming languages often need a parser.

Is Regex Tester free to use?

Yes. Regex Tester is free to use in your browser with no signup required.

Is my data uploaded when I use Regex Tester?

Most FreeToolsBox tools process data locally in your browser. Some pages may load analytics, ads, or third-party services. Avoid entering sensitive data on any online page.

What can I use Regex Tester for?

Test and debug regular expressions against your text. See all matches instantly. Free online regex testing tool.