Regex Tester
Test regex patterns, inspect a token-by-token flow view, and spot likely backtracking or ReDoS risks before they hit production.
gRegex flow graph
使用分组组织子模式,含有重复量词
分组子表达式,可用于捕获、断言或作用域控制
(?... )重复量词,控制前一个片段的重复次数
?字面量字符,需要在输入中原样出现
<字面量字符,需要在输入中原样出现
w字面量字符,需要在输入中原样出现
o字面量字符,需要在输入中原样出现
r字面量字符,需要在输入中原样出现
d字面量字符,需要在输入中原样出现
>字符类,从一组字符中选择一个匹配
[A-Za-z]重复量词,控制前一个片段的重复次数
+字面量字符,需要在输入中原样出现
)匹配空白字符
\s重复量词,控制前一个片段的重复次数
+分组子表达式,可用于捕获、断言或作用域控制
(...)匹配一个数字
\d重复量词,控制前一个片段的重复次数
+字面量字符,需要在输入中原样出现
)Preview
Hello 123 World 456 NoMatch
Backtracking risk analysis
1包含捕获组
low如果你只需要分组而不读取结果,可改成 `(?:...)` 减少不必要的捕获开销。
Matches
2Test 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.
- Type or paste your regex without surrounding slashes, then enable the flags you need (case-insensitive, global, multiline, etc.).
- Paste a representative sample of the input you expect, including edge cases such as empty strings, very long strings, and Unicode characters.
- Inspect the highlighted matches and captured groups. If a group does not appear, double-check the parentheses and escaping.
- 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.
Related tools
Move directly into the next step instead of leaving the site to do adjacent work elsewhere.
JSON Formatter / Validator
Format, minify and validate JSON data
SQL Formatter
Format and beautify SQL queries
Unicode Converter
Convert text to Unicode code points and vice versa
URL Encoder / Decoder
Encode and decode URL components and full URLs
cURL / Fetch / Axios Converter
Parse cURL commands into structured requests and convert them to Fetch, Axios, or Python requests code.
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.