My text looks like this:
Text1 | Text2 | Text3 | Text4 | Text5 | Text6 | Text7
And I want to change text positions like this
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 1The 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.