Editor

Waiting for input or regex execution…

Actions

?
?
?

About Online Regex Tester

Paste some text, write a regex pattern, toggle flags and instantly see what matches. This regex tester uses the same RegExp engine as modern JavaScript runtimes, so what you see here is what you’ll get in your frontend code, Node.js scripts, or server-side validation. Named capture groups, lookarounds and Unicode mode are supported when your runtime supports them.

Why Use This Regex Tester

  • Real-time matching with an optional "live" mode to re-run as you type
  • Structured match list with start index, end index, value and named capture groups
  • Full JavaScript/ECMAScript RegExp syntax support (same engine as your JS runtime)
  • Flag controls: g, i, m, s, u, y – combine and experiment safely
  • Basic performance insight with per-run execution time in milliseconds
  • Text-only summary output for quick copy/paste into tickets, docs or commit messages
  • Excellent for learning: prototype patterns without running a full project or test suite
  • Ideal for everyday tasks: log parsing, validation, URL / ID extraction, quick data cleaning
  • Result list is softly capped to avoid UI freeze when matching large texts

🔧 How to Use the Regex Tester for regex-tester

1

1. Paste or Type Your Test Text

Add the text you want to search through: logs, snippets, CSV fragments, HTML, JSON, anything that’s plain text.

2

2. Write Your Regex Pattern

Enter the regular expression **without surrounding slashes**. For example: <code>\b\w+@\w+\.\w+</code> for a basic email-like pattern, or <code>(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})</code> with named groups.

3

3. Set Flags (g, i, m, s, u, y)

Toggle flags like <code>g</code> (global), <code>i</code> (case-insensitive) or <code>m</code> (multiline). Under the hood, the tester builds <code>new RegExp(pattern, flags)</code> exactly like JavaScript does.

4

4. Inspect Matches & Groups

Review each match with its index, optional end index and capture groups. Named groups appear as a JSON-like map so you can copy them into test fixtures, parsers or documentation.

5

5. Copy the Summary

Use the text summary as a quick report: it lists matches with indices and groups, ready to paste into tickets, code review comments or cheat sheets.

Regex Syntax & Engine Details

Character Classes & Basics

Core building blocks supported by the JavaScript RegExp engine.

PatternMeaningExample
.Any character except line breaks (unless <code>s</code> flag)<code>a.c</code> → matches <code>abc</code>
\d, \w, \sDigits, word chars, whitespace<code>\d+</code> → <code>123</code>
\D, \W, \SNegated versions of the above<code>\S+</code> → non-whitespace runs
[abc]Character set<code>[aeiou]</code> → a single vowel
[^abc]Negated set<code>[^0-9]</code> → non-digit
^, $Start and end of input (or line with <code>m</code>)<code>^Hello</code>, <code>!$</code>

Quantifiers

Repetition of previous tokens, with greedy and lazy behavior.

PatternMeaningExample
?0 or 1 time<code>colou?r</code> → matches <code>color</code> and <code>colour</code>
*0 or more<code>a*b</code> → <code>b</code>, <code>aaab</code>
+1 or more<code>\d+</code> → <code>1</code>, <code>123</code>
{n}Exactly n<code>a{3}</code> → <code>aaa</code>
{n,}At least n<code>\d{3,}</code> → <code>123</code>, <code>1234</code>
{n,m}Between n and m<code>a{2,4}</code> → <code>aa</code>, <code>aaa</code>, <code>aaaa</code>

Groups, Lookarounds & Named Captures

More advanced features provided by modern JavaScript engines.

FeatureSyntaxExample
Capturing groups(...)<code>(\d{3})-(\d{2})</code> → area + suffix
Non-capturing groups(?:...)<code>(?:https?|ftp)://</code>
Backreferences\1, \2, ...<code>(\w)\1</code> → <code>aa</code>, <code>bb</code>
Lookaheads(?=...), (?!...)<code>\w+(?=! )</code> → word before <code>! </code>
Lookbehinds*(?<=...), (?<!...)<code>(?<=#)\w+</code> → text after <code>#</code> (*in modern engines)
Named groups(?<name>...)<code>(?<year>\d{4})</code> → <code>groups.year</code> in results

Flags (Options)

The tester’s flags map directly to JavaScript RegExp flags.

FlagNameEffect
gGlobalFind all matches instead of just the first
iIgnore caseCase-insensitive matching
mMultiline<code>^</code> and <code>$</code> match line boundaries
sDotAll<code>.</code> also matches line breaks
uUnicodeEnables Unicode mode and property escapes in modern engines
yStickyMatch at the current index only (used with <code>lastIndex</code>)

Performance & Safety

The underlying JavaScript engine executes regex synchronously. To keep the UI responsive, the tester caps the number of collected matches (e.g. the first 500 hits in global mode). This helps avoid flooding the UI, but does not replace full performance audits for complex or critical patterns.

Command Line Regex Tools

Once your pattern works here, you can reuse the same or similar regex in your terminal, scripts or CI jobs:

Linux / macOS

Search with grep (extended regex)

grep -E 'pattern' file.txt

Find lines that match a given pattern

Search & replace with sed

sed -E 's/pattern/replacement/g' input.txt > output.txt

Batch substitutions in text files

Windows / PowerShell

PowerShell regex search

Select-String -Pattern '\d{3}-\d{2}-\d{4}' -Path logs.txt

Find US-style SSN patterns in log files (example)

PowerShell regex replace

(Get-Content input.txt) -replace 'old', 'new' | Set-Content output.txt

Simple regex-based replacements

Practical Regex Applications

Web & Frontend Development

  • Validate emails, usernames, slugs or custom IDs in forms
  • Extract route parameters from URLs or paths
  • Quickly prototype patterns for client-side validation
// Basic email-like validation
/^[\w.+-]+@[\w.-]+\.[A-Za-z]{2,}$/i.test(email);
// Route params: /post/123
const match = pathname.match(/^\/post\/(\d+)/);

Logs, Data & Backend

  • Parse timestamps and levels from log lines
  • Normalize whitespace and clean messy text
  • Extract IDs, emails or references from unstructured content
// Collapse repeated whitespace
const normalized = text.replace(/\s+/g, ' ').trim();
// Simple log line matcher
const m = line.match(/\[(?<date>\d{4}-\d{2}-\d{2})] (?<level>INFO|ERROR): (?<msg>.*)/);

Data Cleaning & Quick Scripts

  • Strip unwanted HTML tags or attributes before parsing
  • Pull all URLs, emails or IDs from a long blob of text
  • Prepare dataset fields for import into another system

❓ Frequently Asked Questions

Why isn’t my regex matching anything?

Common pitfalls: 1) Special characters not escaped (like ., ?, +), 2) Forgetting the g flag when expecting multiple matches, 3) Missing anchors (^, $) or word boundaries (\b), 4) Using features your JavaScript engine doesn’t support yet (such as some lookbehinds). Try simplifying the pattern and adding pieces back gradually.

⏱️What does the execution time (ms) mean?

Each run is timed using performance.now(). The value is a rough single-run measurement of how long the regex took to execute on the current input. It’s useful for spotting obviously expensive patterns, but it’s not a full benchmark or a guarantee of production performance.

🔍What’s the difference between first match and global mode?

Without the g flag, JavaScript returns only the **first** match (if any). With g, the tester uses input.matchAll() to collect **all** matches (capped to a safe maximum), including indices and capture groups. Use global mode whenever you care about multiple occurrences.

🌍Does this support Unicode and <code>\p{...}</code> escapes?

Yes, when your JavaScript engine supports it. Enable the u flag to opt into Unicode mode, which unlocks things like \p{Letter} or \p{Script=Greek} in modern browsers and recent Node.js versions.

⚠️Can this detect catastrophic backtracking?

The tester can hint at slow patterns via the execution time, but it cannot fully prevent catastrophic backtracking: the underlying engine still runs synchronously. Use this tool as an early warning system, then benchmark and review complex patterns carefully in your own codebase.

Pro Tips

Best Practice

Build your regex in small pieces. Start with something simple that matches, then add anchors, groups and quantifiers step by step.

Best Practice

Use named capture groups (<code>(?<name>...)</code>) whenever possible. They make your matches self-documenting and much easier to read during code reviews.

Best Practice

Be careful with <code>.*</code> and nested quantifiers. They can cause heavy backtracking on large inputs. Make patterns more specific or limit repetition with <code>{n,m}</code>.

Best Practice

When debugging, temporarily remove the <code>g</code> flag and focus on the first match to simplify the mental model.

Additional Resources

Other Tools