You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用特殊符号@替换双换行符以适配翻译工具行号匹配需求

Fixing Double Line Break Replacement for Your Translation Tool

Hey there! I get why that regex wasn't working for you—let's get this sorted so your translation output matches the original line numbers perfectly.

The Problem Breakdown

You've got text where every line (including the last one) is followed by two line breaks (either \n\n for Unix-style or \r\n\r\n for Windows-style), and you need to replace those double breaks with @ followed by a single line break to keep your line structure intact.

The Correct Regex & Replacement

Here's the regex that will target all double line breaks, regardless of whether they're Windows or Unix format:

  • Find: (\r?\n){2}
  • Replace: @$1

How it works:

  • (\r?\n) matches a single line break—either \n (Unix) or \r\n (Windows). The parentheses capture this as a group so we can reuse it in the replacement.
  • {2} tells the regex to look for exactly two of these line breaks in a row.
  • @$1 replaces the double break with @ followed by the captured single line break, ensuring your line structure stays consistent while adding the required special character.

Example Test

Let's apply this to your sample data:
Original Input:

Translated data line 1

Translated data line 2

Translated data line 3

Translated data line 4

(Note: Each line is followed by two line breaks)

After Replacement:

Translated data line 1@
Translated data line 2@
Translated data line 3@
Translated data line 4@

Edge Case Handling

If your text has inconsistent line breaks (mix of single and double), this regex will still work because it only targets pairs of line breaks—no accidental changes to single line breaks you might need to keep.


内容的提问来源于stack exchange,提问作者stackmike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 20:27:36