如何替換第四次出現的 | notepad++ 中每行都有空格

如何替換第四次出現的 | notepad++ 中每行都有空格

我有以下巨大的隨機數據

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

螢幕截圖(之前):

在此輸入影像描述

螢幕截圖(之後):

在此輸入影像描述

相關內容