Tiny Online Tools logoTiny Online Toolssearch搜索工具…grid_view全部工具
首页chevron_right开发者工具chevron_right正则替换工具正则替换工具

正则替换工具

在浏览器中使用正则表达式替换文本。

相似工具

正则提取器

正则提取器

在浏览器中使用正则表达式从文本里提取匹配内容。

正则拆分工具

正则拆分工具

在浏览器中使用正则表达式拆分文本。

User Agent 解析器

User Agent 解析器

从 user agent 字符串解析浏览器、操作系统和设备信息。

图片格式转换

图片格式转换

在JPG、PNG、WebP等格式之间转换图片。

CSV 排序工具

CSV 排序工具

按所选列对 CSV 行进行排序。

视频分辨率转换器

视频分辨率转换器

直接在浏览器中将视频转换为不同的输出分辨率。

批量 QR 码生成器

批量 QR 码生成器

从 URL 或文本列表一次生成多个 QR 码。

apps

更多工具

浏览我们完整的免费在线工具集合。

Advanced Find & Replace with Regex Patterns

Find and replace is essential for refactoring and text 转换ation, but simple string replacement is limited. You can't easily replace all variations of a pattern, rearrange matched content, or conditionally replace based on context. Manual find-and-replace in an editor is slow for complex changes. This Regex Replace Tool lets you define patterns and see replacements instantly before applying them.

Write a regex pattern, specify a replacement using capture groups, and watch the 转换ation happen in real time. Perfect for bulk code refactoring, data 转换ation, and complex text processing.

Powerful Replacement Syntax

Literal Replacement: Simply replace all matches with fixed text.

Capture Group References: Use $1, $2, etc. to reference captured groups, rearranging matched content:

  • Pattern: (\\w+)\\s+(\\w+) (first and last name)
  • Replacement: $2, $1 (last name, first name)
  • Example: "John Smith" → "Smith, John"

Special Replacements:

  • $&: The entire matched string
  • $`` : Text before the match
  • $': Text after the match

Common Code Refactoring Scenarios

Rename Variables Across Files: Find all instances of a variable pattern and rename them. For example, change user_id to userId everywhere:

  • Pattern: user_id
  • Replacement: userId

For complex patterns like function_name( that vary:

  • Pattern: (\\w+_\\w+)\\(
  • Replacement: Use a pattern to extract and 转换 the name

Re格式化 Data: 转换 data 格式化s without manual editing. 转换 date 格式化s, phone numbers, or address 格式化s by extracting parts and recombining them:

  • Pattern: (\\d{4})-(\\d{2})-(\\d{2}) (YYYY-MM-DD)
  • Replacement: $3/$2/$1 (DD/MM/YYYY)

Code Modernization: Update code syntax across files. For example, update import statements, function signatures, or API calls:

  • Old: require('module')
  • New: import 'module'

HTML/XML 转换ation: Restructure or update markup by finding patterns and rewriting them with rearranged content.

Log Cleanup: Remove or 转换 sensitive data in logs. Find email addresses, phone numbers, or IDs and replace them with redacted versions:

  • Pattern: \\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b
  • Replacement: [REDACTED]

Live Preview Before Applying

See the 转换ation in real time. This is crucial—test your pattern and replacement on a sample before applying to entire documents. Mistakes in find-and-replace can corrupt large files quickly.

Full Regex Flag Support

  • g (global): Replace all matches, not just the first
  • i (case-insensitive): Replace regardless of case
  • m (multiline): Treat line boundaries as match anchors
  • s (dotAll): Dot matches newlines

Copy & Use Results

Once satisfied with the 转换ation, copy the result to your 剪贴板 and paste it directly into your editor or files.

100% 本地处理

All find-and-replace happens in your 浏览器. Your content never leaves your machine, making this safe for proprietary code, sensitive data, or internal documentation.