简体   繁体   English

Notepad++ 删除两个特定字符串之间的换行符

[英]Notepad++ remove linebreak in between two specific strings

I have something like this我有这样的东西

\text
This is a sentence.
This is another sentence.
\endtext

I want to remove the line break in between the two sentences in all instances of \text and \endtext.我想删除 \text 和 \endtext 的所有实例中两个句子之间的换行符。 In order to look like this为了看起来像这样

\text
This is a sentence. This is another sentence.
\endtext

But of course where it gets complicated is that there are also line breaks after \text and before \endtext.但当然,它变得复杂的地方是在 \text 之后和 \endtext 之前也有换行符。 These I want to keep.这些我想保留。 So, logically and in english speaking, what I was looking to do is something like所以,从逻辑上讲,用英语来说,我想做的是

(after "\text\n") (remove all instances of \n) (before "\n\endtext") (在 "\text\n" 之后) (移除 \n 的所有实例) (在 "\n\endtext" 之前)

but since I'm not very good at regex, I'm not sure how that would be written out in that language.但由于我不太擅长正则表达式,所以我不确定如何用该语言写出来。 Could someone help?有人可以帮忙吗?

Notepad++ supports PCRE. Notepad++ 支持 PCRE。

You can use this regex to search:您可以使用此正则表达式来搜索:

(?:\\text\R|(?<!\A)\G).*\K\R(?!\\endtext)

Replace this with a space.将其替换为空格。

RegEx Demo正则表达式演示

RegEx Breakdown:正则表达式细分:

  • (?: : Start non-capture group (?: : 启动非捕获组
    • \\text : Match \text \\text :匹配\text
    • \R : Match a line break \R :匹配一个换行符
    • | : OR : 或者
    • (?<!\A)\G : Start from the end of the previous match. (?<!\A)\G :从上一场比赛结束开始。 (?<!\A) is to make sure that we are not the start position (?<!\A)是为了确保我们不是开始 position
  • ) : End non-capture group ) : 结束非捕获组
  • .* : Match 0 or more any character except line break .* :匹配0个或多个除换行符以外的任何字符
  • \K : Reset match info \K :重置匹配信息
  • \R : Match a line break \R :匹配一个换行符
  • (?!\\endtext) : Negative lookahead to make sure that we don't have Match \endtext` right next to the current position (?!\\endtext) :否定前瞻以确保我们没有在当前 position 旁边Match \endtext`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM