跳至主要内容
Redmoon Converters
⚙️ 开发者工具

正则表达式测试器(附通俗解读)

实时测试任意正则表达式,高亮显示匹配结果,并对每个标记进行通俗解读。内置常用模式库(邮箱、URL、IPv4、电话),并支持生成可分享链接。

匹配项

匹配列表

#匹配项索引分组

通俗解析

    计算原理

    匹配使用原生 JavaScript RegExp 引擎。解析器会逐个 token 分析模式:字符类(\\w \\d \\s),量词(* + ? {n,m}),锚点(^ $ \\b),以及分组、或运算和常见转义符。

    无效模式会被提示,而不会导致程序崩溃。使用 g 标志查找所有匹配项;使用 i 标志实现大小写不敏感匹配。

    计算原理

    Matching runs on your browser's own JavaScript RegExp engine, so results are exactly what new RegExp(pattern, flags) produces. With the g flag on, exec is called in a loop and every match is collected with its string index and capture groups; zero-length matches nudge lastIndex forward by one to avoid an infinite loop. The plain-English breakdown is separate: it walks the pattern character by character and labels each token it recognises.

    The six flag checkboxes are the quickest way to change behaviour. Only g is ticked by default, and it decides whether you get the first match or all of them; i, m, s, u and y are off. The pattern box starts with a simple email-shaped expression tested against a sentence containing three addresses. Five preset buttons, Email, URL, IPv4, US phone and ISO date, replace both the pattern and the test string together.

    Because this is the JavaScript flavour, PCRE-only syntax such as possessive quantifiers, recursion, or the \A and \z anchors will not behave the way it does in PHP, Python or Perl. The explainer is a flat left-to-right scan rather than a parse tree, so it never shows nesting, and it has no entry for lookbehind or named groups, breaking (?<=x) into a capturing group plus literals. Matching stops after 5,000 results and the table lists 200.

    常见问题

    Why am I only getting one match?

    The g flag controls that. With g unticked the tool calls exec once and reports the first match only; tick it and the pattern is run repeatedly across the entire test string until no further matches remain. It is ticked by default.

    Does this tester support Python or PCRE regex syntax?

    It runs the JavaScript engine only. Everyday syntax behaves identically, but PCRE-specific constructs will either raise an error or match differently. Anything valid in a browser's RegExp constructor works, including the u and y flags exposed as checkboxes.

    How do I see what my capture groups matched?

    The match list table has a Groups column showing $1, $2 and so on for every match, with an empty-set symbol where a group took part in no match. Non-capturing groups written as (?:...) deliberately produce no entry there.

    What does the plain-English breakdown actually cover?

    Escapes such as \d, \w, \s and \b, the start and end anchors, the dot, alternation, capturing and non-capturing groups, positive and negative lookaheads, character classes, the three basic quantifiers and {n,m} ranges. Anything else is reported as a literal character.

    Is my test data sent to a server?

    No. The pattern and the test string are evaluated in your own browser by its built-in regex engine, with no upload and no server round trip. There is also no save or share link, so refreshing the page resets both fields to the defaults.

    别名

    regex testerregex to englishregex explainerregex visualizer

    相关工具