Switch word postions in Notepad ++

流过昼夜 提交于 2019-12-20 07:26:19

问题


My text looks like this:

Text1 | Text2 | Text3 | Text4 | Text5 | Text6 | Text7 

And I want to change text positions like this

Text1 | Text4 | Text5 | Text6 | Text2| Text3 | Text7 

And if it's possible to remove the | between Text 4, 5, 6, so that it looks like

Text1 | Text4 Text5 Text6 | Text2 | Text3 | Text7

If it is not possible, I'll be happy if the first problem is solved.


回答1:


You may use

^([^|]*\|)((?:[^|]*\|){2})((?:[^|]*\|){3})

And replace with $1$3$2.

Details:

  • ^ - start of a line
  • ([^|]*\|) - Group 1 ($1) capturing zero or more chars other than | and then a literal |
  • ((?:[^|]*\|){2}) - Group 2 ($2) capturing 2 sequences of the same pattern as in Group 1
  • ((?:[^|]*\|){3}) - Group 3 ($3) capturing 2 sequences of the same pattern as in Group 1

The order is changed with the order of the backreferences in the replacement pattern.

To remove the 2nd, 3rd and 4th |, use a similar expression:

Find what: ^([^|]*\|)([^|]*)\|([^|]*)\|([^|]*)
Replace with: $1$2$3$4

Basically, you just manipulate the capturing group boudaries and the order of the backreferences in the replacement pattern, that is all.



来源:https://stackoverflow.com/questions/39223508/switch-word-postions-in-notepad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!