Regex Tester

Two-column layout like other tools: left is the pattern (body only, no slashes) plus g/i/m/s/u/y toggles; right is the sample text. Below: highlights, match list with capture groups and index spans—same ECMAScript RegExp behaviour as your browser.

What this RegExp test proves—and what it deliberately does not prove

Regular expressions are tiny programs over text: the same pattern string plus the same flags must behave like the new RegExp constructor in a modern browser because this page evaluates matches with the ECMAScript engine, not PCRE, Python, Ruby, or Java—if your logs or services use another dialect, treat anything you copy from here as a first draft and re-test in that runtime.

The UI separates pattern from flags so you are not fooled by slash confusion: writers often paste a full /pattern/gi literal into a field that expects only the middle part and then wonder why the global flag vanished; here the literal is only the pattern body and each flag has an explicit toggle. When you are comparing two dump files line by line, patterns and samples still land in different buffers—use side-by-side text compare there and reserve this page for “does this extractor grab the substring I think it grabs?”.

Matches return zero-based start–end indices and optional capturing groups so you can wire the same mental model as String.match, RegExp.exec, and matchAll in application code; they do not run your replacement strategy or split pipeline—after you trust the pattern, move the verified substring rules into your bundler, API layer, or editor macro, optionally pasting through JavaScript formatter when the pattern is embedded in source.

Engine rules, flag semantics, and capture numbering that follow ECMAScript

How the full match, numbered captures, and optional named groups relate to group 0 and RegExp.exec

  1. Group 0 is always the entire substring that satisfied the pattern for that match attempt; numbered groups 1…n appear in left-to-open-paren order, which matters when you nest alternation.
  2. Named groups (?<id>…) show up with their names only when the pattern is valid under the chosen flags; duplicate names in one pattern are a syntax error, unlike some PCRE-only conveniences.
  3. The index span is half-open in spirit for humans here: the UI prints start–end where end is the last inclusive character index of the match so you can eyeball overlap; copy the values into code that expects exclusive end positions by adding one when needed.

What flags g, i, m, s, u, and y change for line breaks, dot behaviour, and Unicode

  1. g finds every non-overlapping match and keeps lastIndex advancing in the real RegExp object—without it you only observe the first match, which is how validation patterns differ from extraction patterns.
  2. m makes the caret and dollar anchors refer to line boundaries inside a multiline paste; without it a whole syslog buffer can look like “one line” to the anchors.
  3. s (dotAll) lets the dot cross newline boundaries; combined with m you can express “block inside a stanza” without awkward negated-class gymnastics.
  4. u turns on Unicode-aware parsing for identifiers, \p{…} property escapes where supported, and sane handling of astral characters; y pins the next match attempt to the current lastIndex, which models sticky tokenisers.

Why greedy versus lazy quantifiers change runtime cost and stack depth

  1. By default star and plus quantifiers consume as much as possible and backtrack only when a later part of the pattern fails; that is fast when the tail is discriminating and catastrophic when it is not.
  2. Appending a question mark to a quantifier makes it lazy (take the smallest stretch that still allows the rest to succeed), which can reduce accidental huge grabs in log lines but can increase backtracking on pathological strings.
  3. When a pattern “hangs” on multi-megabyte paste, simplify anchors, narrow character classes, or pre-split the file—regex is rarely the right tool for whole-file scanning without chunking.

Literal escapes, surrogate pairs, and why pasted code differs from pasted prose

  1. A backslash in the pattern field is one keyboard backslash; when you lift a pattern from C++ or Java source you may need to halve the escapes compared to what the string literal contained.
  2. Emoji and rare scripts may use surrogate pairs in UTF-16; the u flag affects whether those code points are treated as single characters for dot and {n} counts.
  3. If you need to see the exact bytes your CMS will store, cross-check lengths with text statistics after extraction.

Where quick browser-side RegExp tests save review time

Pulling structured fields without standing up a JSON parser

A one-line API response in a ticket is often enough to sanity-check a pattern that pulls the orderId value from JSON-shaped text before you paste the same expression into a monitoring alert; confirm group 1 is the identifier you expect, then harden with real parsing in code.

Reconstructing HTTP client IP and status from nginx-style access lines

When a dotted IPv4 run plus a lazy span and a three-digit HTTP status fit your log vendor’s quoting, group 1 is the IPv4-looking token and group 2 is the status code—if the format wraps quoted fields differently, tighten the middle non-greedy span before shipping a dashboard filter.

Sanity-checking hrefs and opaque IDs before regex lands in a sanitizer

Patterns that read URL tokens from href attributes or use UUID-shaped character classes find candidates in HTML fragments; they are not a security boundary—pair the extraction preview here with your CSP, allow-lists, and DOM parsing rules.

Verifying CSV-ish or log lines before a migration script runs once

When columns moved between exports, a staged pattern on a sample row catches delimiter shifts early; for whole-file semantic comparison of settings, prefer structured diff tooling after you normalize with JSON formatter on both sides.

Common questions

How do I test a regular expression online for JavaScript before I paste it into my app?
Put the pattern body (the part between the slashes in a /…/flags literal) in the pattern field, paste sample text, and set the same flags as in new RegExp or a literal—you will get match count, spans, and captures like RegExp.exec. To check whether two samples differ invisibly before you tune the pattern, use text compare.
Do I type the slash characters around the pattern body in the pattern field?
No—slashes are delimiters for JavaScript literals, not part of the pattern string passed to the constructor. Put a caret plus digits in the field and choose m or g with the buttons; typing leading/trailing slash characters would make those characters part of the pattern and break anchors.
Why does my Python or Java regex work but this page says invalid or matches nothing?
Those runtimes use different escape rules, flag letters, and lookahead limits. ECMAScript uses (?<name>…) for names, requires u for some Unicode property forms, and does not implement PCRE recursion. Port the pattern by reconstructing it for JS, then re-test here before merging into frontend bundles or Node services.
What does group 0 mean in the match list?
Group 0 is the entire substring the engine accepted as one match; groups 1+ are capturing parentheses in source order. That mirrors match[n] from String.match with g and the return array from RegExp.exec without g.
Why am I seeing unexpected matches or no matches on this page?
This tool runs ECMAScript RegExp in the browser using only the pattern field and the flag toggles you set here—nothing else influences the result. If the list is empty or the count seems wrong, re-check the field has only the pattern body (no wrapping slashes), g and m match your intent, backslashes are not doubled from copied source literals (double backslash-d in a Java string is single backslash-d here), and the sample has no hidden CRLF or zero-width characters; text compare helps you inspect the paste in detail.
Can I test search-and-replace or String.replace strategies here?
This page focuses on match inspection—which spans fire and what each capture holds. After you validate captures, run replacements in your runtime, IDE, or a dedicated replacer; for large scripted transforms on JSON-like text, pretty-print both sides with JSON formatter first so line-oriented tools agree.
How do I debug catastrophic backtracking or “pattern takes forever” on a long paste?
Narrow quantifiers, add required delimiters, or split the file into lines or records before matching. Nested star quantifiers on unbounded text are the usual suspect; simplify to anchored fragments. If you only need character counts or byte lengths for thresholds, verify with text statistics instead of regex alone.
Should I validate email, URLs, or phone numbers with only a regex?
Regex is good for plausibility and extraction previews; domain rules, internationalisation, and authentication belong to dedicated validators and APIs. Use mailbox-link patterns here to see false positives in real CRM exports, then layer canonical checks in code.

Patterns to paste into the pattern field

  • [\w.+-]+@[\w.-]+\.\w+Mailbox-shaped token for mixed-case prose — try flags gi when normalising marketing copy
  • https?://[^\s"'<>]+http/https URL candidates in logs or chat — flag g enumerates every non-whitespace run
  • [0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}UUID-shaped tokens in traces — still verify version and entropy in business logic
  • \d{4}-\d{2}-\d{2}ISO-like dates yyyy-MM-dd in filenames or reports
  • \b(?:\d{1,3}\.){3}\d{1,3}\bIPv4-shaped quads — not strict 0–255 validation
  • [?&]id=([^&]+)First id= query parameter — group 1 is the captured value