跳到主要内容
uencoder

Find 和替换文本 using regular 表达式

Search 为 patterns (不仅 字面量 strings) 在文本和 替换 matches 具有模板该 能够参考 capture groups.

  1. 1

    Regex 查找-和-替换 goes beyond 字面量 substitution: 它 matches patterns (所有 email addresses, 所有 numbers, repeated whitespace) 和能够 use captured submatches 在 replacement (e.g. swap 第一和 最后 name).

  2. 2
    正则表达式替换器 →

    Enter regex 模式, flags (g 为全局, i 为情况-insensitive), 和 replacement 模板 (use $1, $2 为 capture groups). tool shows 所有 matches 和 replaced 输出.

  3. 3
    正则表达式测试器 →

    测试模式第一在 regex tester 到 confirm 它 matches 什么你 expect 之前 applying replacement — 此 avoids catastrophic replacements 开 unexpected 输入.

常见问题

什么是 差集之间 $1 和 \1 在 replacement?
$1 是 JavaScript replacement syntax; \1 是 sed/Perl syntax. Use $1 在 JS-based tools. Named capture groups 能够是 referenced as $<name> 在现代 JS.
My regex 是 too greedy — 如何 I 限制 matches?
Use non-greedy quantifiers (*?, +?) 到匹配 shortest 可能字符串, 或替换。* 具有更多特定字符 classes. 总是测试开 边界情况 — greedy regex 是最多常见源 的 unexpected replacements.

解决此任务的工作流

相关工具