首页 > 解决方案 > 替换记事本++中的每隔一个空行

问题描述

Notepad ++中有没有办法替换所有其他空白行?填充行的数量是随机的,空行的出现也是随机的。

这种差异是否可以通过不均匀的间距进行,或者是否超出了记事本中的表达式范围?

编辑:我正在寻找替换每第二次出现的空行。

例如:-

    Bed
    Bee

    [BLANK A]

    Bible
    Bible
    Bird
    Bomb

    [BLANK B]

    Book
    Boss
    Bottle
    Bowl
    Box

    [BLANK A]

    Boy
    Brain
    Bridge
    Butterfly
    Button
    Cappuccino
    Car

    [BLANK B]

    Car-race
    Carpet
    Carrot
    Cave
    Chair

    [BLANK A]

    Chess Board
    Chief
    Child
    Chisel
    Chocolates

其中 A 和 B 应分别更换。

标签: notepad++

解决方案


  • Ctrl+H
  • 找什么:((?:.+\R)+)(\R)(?:((?:.+\R)+)(\R))?
  • 用。。。来代替:$1[BLANK A]$2(?3$3[BLANK B]$4)
  • 检查 环绕
  • CHECK 正则表达式
  • 取消选中 . matches newline
  • Replace all

解释:

(               # group 1 (will contain consecutive non blank lines)
  (?:           # non capture group
    .+          # 1 or more any character but newline
    \R          # any kind of linebreak (i.e. \r, \n, \r\n)
  )+            # end group, may appear 1 or more times
)               # end group 1
(\R)            # group 2, any kind of linebreak (i.e. first blank line)
(?:             # non capture group
  (             # group 3, same pattern as in group 1
    (?:
      .+
      \R
    )+
  )
  (\R)          # group 4, any kind of linebreak (i.e. second blank line)
)?              # end group, optional

替代品:

$1              # content of group 1 (non blank lines)
[BLANK A]       # replacement for first blank line
$2              # content of group 2, (a linebreak)
(?3             # if group 3 exists:
    $3              # content of group 3 (non blank lines)
    [BLANK B]       # replacement for second blank line
    $4              # content of group 4, (a linebreak)
)               # end condition

屏幕截图(之前):

在此处输入图像描述

屏幕截图(之后):

在此处输入图像描述


推荐阅读