我在 Notepad++ 中有一些如下所示的文本数据,我想找到大于 7 ;
(分号)的行,并且在第 7 个分号之后该行应该移动到下一行。
sdkjfkdf;asdkjfhkhsdf;sdjfhkhkf;sadjfhks;dhhdhd;jfksdf;dfhkk;jhdfkksdf;kjdfhksf;
sdkjfkdf;asdkjfhkhsdf;sdjfhkhkf;sadjfhks;dhhdhd;jfksdf;dfhkk;jhdfkksdf;kjdfhksf;kasjdjkashd;
sdkjfkdf;asdkjfhkhsdf;sdjfhkhkf;sadjfhks;dhhdhd;jfksdf;dfhkk;jhdfkksdf;kjdfhksf;skdjjd;
输出应该是:
sdkjfkdf;asdkjfhkhsdf;sdjfhkhkf;sadjfhks;dhhdhd;jfksdf;dfhkk;
jhdfkksdf;kjdfhksf;
sdkjfkdf;asdkjfhkhsdf;sdjfhkhkf;sadjfhks;dhhdhd;jfksdf;dfhkk;
jhdfkksdf;kjdfhksf;kasjdjkashd;
sdkjfkdf;asdkjfhkhsdf;sdjfhkhkf;sadjfhks;dhhdhd;jfksdf;dfhkk;
jhdfkksdf;kjdfhksf;skdjjd;
问题 2 是:
不是以数字开头的行应该移动到上一行的末尾。
1237;sdkjjf;djdkd;djfhfk;
sjdjdjd;skks;
12344;sjdjjd;djdjjd;
*ddjdjdj
.sjjs;
#jdjjdjd
输出应该是:
1237;sdkjjf;djdkd;djfhfk;sjdjdjd;skks;
12344;sjdjjd;djdjjd;*ddjdjdj.sjjs;#jdjjdjd
答案1
对于第一个问题:
- Ctrl+H
- 找什么:
^(?:.+?;){7}\K
- 替换为:
\n
或\r\n
适用于 Windows EOL - 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
^ # beginning of line
(?: # non capture group
.+? # 1 or more any character but newline
; # semicolon
){7} # end group, must appear 7 times
\K # forget all we have seen until this position
截图(之前):
截图(之后):