Notepad++ 将以字符串开头的行拆分为每行一个空格

Notepad++ 将以字符串开头的行拆分为每行一个空格

我有一些像这样的文字

Read the following aloud
Orange Mango Lemon Apple

Read the following aloud 
red yellow blue white green black purple

我需要将它拆分成这样

Read the following aloud
Orange
Mango
Lemon
Apple

Read the following aloud 
Red
Yellow
Blue
White
Green
Black
Purple

我试过使用正则表达式,但无法只选择空格。我发现我可以选择整行

任何指示都将不胜感激

答案1

  • Ctrl+H
  • 找什么:(\w+)\h+(?=.+(?:\R\R|\Z))
  • 用。。。来代替:$1\n
  • 检查环绕
  • 检查正则表达式
  • 取消选中. matches newline
  • Replace all

解释:

(\w+)       # group 1, 1 or more word characters
\h+         # 1 or more horizontal spaces
(?=         # positive lookahead, make sure we have after:
    .+      # 1 or more any character but newline
    (?:     # start non capture group
      \R\R  # 2 linebreaks
     |      # OR
      \Z    # end of file
    )       # end group
)           # end lookahead

替代品:

$1          # content of group 1
\n          # linefeed, you can use "\r\n"

给定示例的结果:

Read the following aloud
Orange
Mango
Lemon
Apple

Read the following aloud 
red
yellow
blue
white
green
black
purple

屏幕截图:

在此处输入图片描述

相关内容