问题
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