Switch word postions in Notepad ++

前端 未结 1 1968
小蘑菇
小蘑菇 2021-01-26 06:02

My text looks like this:

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

And I want to change text positions like this

         


        
相关标签:
1条回答
  • 2021-01-26 06:42

    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.

    0 讨论(0)
提交回复
热议问题