转换
Source: This is source 1
Description : This is the description of source 1
Source: This is source 2
Description : This is a description of source 2
变成这样:
Description : This is a source 1: This is the description of source 1
Description : This is a source 2: This is the description of source 2
我见过的所有示例都将第 2 行附加到第 1 行,如下所示:
(^Source.*$)(\r\n)
\1
我需要将第 1 行附加到第 2 行,将第 3 行附加到第 4 行等等。
答案1
- Ctrl+H
- 找什么:
^Source(:.+)\R(Description\h+)
- 用。。。来代替:
$2$1
- 查看 相符
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
* - Replace all
解释:
^ # beginning of line
Source # literallly
(:.+) # group 1, colon and 1 or more any character but newline
\R # any kind of linebreak (i.e. \r, \n, \r\n)
( # group 2
Description # literally
\h+ # 1 or more horizontal spaces
) # end group 2
替代品:
$2 # content of group 2
$1 # content of group 1
屏幕截图(之前):
屏幕截图(之后):