Find 和替换文本 using regular 表达式
Search 为 patterns (不仅 字面量 strings) 在文本和 替换 matches 具有模板该 能够参考 capture groups.
- 1
Regex 查找-和-替换 goes beyond 字面量 substitution: 它 matches patterns (所有 email addresses, 所有 numbers, repeated whitespace) 和能够 use captured submatches 在 replacement (e.g. swap 第一和 最后 name).
- 2 正则表达式替换器 →
Enter regex 模式, flags (g 为全局, i 为情况-insensitive), 和 replacement 模板 (use $1, $2 为 capture groups). tool shows 所有 matches 和 replaced 输出.
- 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.
解决此任务的工作流
相关工具
正则表达式替换器
使用正则表达式查找并替换文本。免费、隐私本地化、100% 客户端运行。 工具
正则表达式测试器
测试正则表达式,支持匹配高亮、捕获组和替换预览。免费、隐私本地化、100% 客户端运行。支持全局(g)、忽略大小写(i)、多行(m)、dotAll(s)标志位,匹配在带超时的 Web Worker 中运行以避免灾难性回溯冻结页面。 工具
大小写转换器
在 UPPER、lower、Title、camelCase、PascalCase、snake_case、kebab-case、CONSTANT_CASE 和 Sentence case 等格式之间转换文本。免费、隐私本地化、100% 客户端运行。自动识别混合输入(如 hello_worldFoo),按空格/下划线/连字符/大写边界拆分,适合变量命名、API 字段、CSS 类名和常量定义的格式转换。 工具