如何在记事本++中用空格替换每行中第四次出现的|

如何在记事本++中用空格替换每行中第四次出现的|

我有以下大量随机数据

1231286234|453|1234|xxx|aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx| aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx |aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx | aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv

行数很大,数据是随机的,我希望它们像

1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv    
1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv

答案1

这适用于您提供的示例。

Find what: (\w*\|\w*\|\w*\|\w*)([\|\s]*)([\w\|]*)
Replace with: \1 \3

Search mode: Regular expression

例子

答案2

  • Ctrl+H
  • 找什么:^(?:[^|]+\|){3}.*?\K\h*\|\h*
  • 替换为: <-- 一个空格
  • 查看 环绕
  • 查看 正则表达式
  • 取消选中 . matches newline
  • Replace all

解释:

^               # beginning of line
  (?:           # start non capture group
    [^|]+       # 1 or more non pipe
    \|          # a pipe, have to be escaped as it's special character for regex
  ){3}          # end group, must appear 3 times
  .*?           # 0 or more any character but new line, not greeedy
  \K            # forget all we have seen until this position
  \h*           # 0 or more horizontal spaces
  \|            # a pipe, have to be escaped as it's special character for regex
  \h*           # 0 or more horizontal spaces

屏幕截图(之前):

在此处输入图片描述

屏幕截图(之后):

在此处输入图片描述

相关内容