</>

Regex Tester

Test regex patterns, inspect a token-by-token flow view, and spot likely backtracking or ReDoS risks before they hit production.

/ / g
Flags:

Regex flow graph

使用分组组织子模式,含有重复量词

#1 group

分组子表达式,可用于捕获、断言或作用域控制

(?... )
#2 quantifier

重复量词,控制前一个片段的重复次数

?
#3 literal

字面量字符,需要在输入中原样出现

<
#4 literal

字面量字符,需要在输入中原样出现

w
#5 literal

字面量字符,需要在输入中原样出现

o
#6 literal

字面量字符,需要在输入中原样出现

r
#7 literal

字面量字符,需要在输入中原样出现

d
#8 literal

字面量字符,需要在输入中原样出现

>
#9 class

字符类,从一组字符中选择一个匹配

[A-Za-z]
#10 quantifier

重复量词,控制前一个片段的重复次数

+
#11 literal

字面量字符,需要在输入中原样出现

)
#12 class

匹配空白字符

\s
#13 quantifier

重复量词,控制前一个片段的重复次数

+
#14 group

分组子表达式,可用于捕获、断言或作用域控制

(...)
#15 class

匹配一个数字

\d
#16 quantifier

重复量词,控制前一个片段的重复次数

+
#17 literal

字面量字符,需要在输入中原样出现

)

Preview

Hello 123 World 456 NoMatch

Backtracking risk analysis

1

包含捕获组

low

如果你只需要分组而不读取结果,可改成 `(?:...)` 减少不必要的捕获开销。

Matches

2
#1 Hello 123 at 0–9
word: "Hello"
#2 World 456 at 10–19
word: "World"

Test regular expressions interactively before they reach production code

Regular expressions are powerful but unforgiving. A pattern that looks correct can quietly accept invalid input, reject valid input, or run catastrophically slowly on adversarial input. This page lets you test patterns against sample text, see captured groups, switch flags, and explore matches before pasting the final pattern into code, validation rules, log filters, or migration scripts.

  1. Type or paste your regex without surrounding slashes, then enable the flags you need (case-insensitive, global, multiline, etc.).
  2. Paste a representative sample of the input you expect, including edge cases such as empty strings, very long strings, and Unicode characters.
  3. Inspect the highlighted matches and captured groups. If a group does not appear, double-check the parentheses and escaping.
  4. Iterate on the pattern until it accepts every valid input and rejects every invalid input you can think of.

The danger of regex is not only failure, but near-success

Many regular expressions seem correct on toy examples and then break under real traffic. Some match too much, some miss edge cases, and some trigger catastrophic backtracking that burns CPU under load.

That makes regex tools especially good candidates for rich supporting text. Developers need to understand anchors, grouping, quantifiers, greediness, Unicode handling, and backtracking behavior, not only whether the current sample matches.

A practical regex strategy for production code

In production, regex should solve bounded problems, not replace full parsing. Email addresses, URLs, dates, and log lines are often better handled with a combination of coarse matching plus domain-specific validation.

Another best practice is to keep a sample corpus of known-failing inputs. Real examples are more valuable than intuition once the pattern grows beyond a few tokens.

Best use cases

  • Validating user input fields such as email, phone number, or product codes.
  • Searching log files and code with grep, ripgrep, or your editor`s find dialog.
  • Writing data migration scripts that need to extract substrings from messy text.

Common mistakes to avoid

  • Backtracking-heavy patterns (nested quantifiers, alternations on the same prefix) can take seconds or minutes on adversarial inputs. Prefer atomic groups or possessive quantifiers when supported.
  • Validating email addresses with a regex is famously fragile. Most production code should use a library or simply check for a single `@` and a dot.
  • Forgetting the global flag in JavaScript means `String.replace` only changes the first occurrence.

FAQ

Which regex flavor does this tool use?

The browser's built-in JavaScript regex engine (ECMAScript). Patterns that work here will work in JavaScript runtimes; PCRE-only features such as lookbehinds older than ES2018 may behave differently in other languages.

How do I test a multiline pattern?

Enable the `m` flag and use `^` and `$` to anchor lines. Without `m`, those anchors only match the start and end of the entire string.

Why does my pattern hang the page?

You probably have catastrophic backtracking. Simplify the pattern, anchor it, or rewrite the alternatives so they cannot all match the same prefix.

Cookie Consent

We use cookies to enhance your experience and show relevant ads. You can customize your preferences.