Macro for Open, Find and Replace and Save
-
@Lycan-Thrope :
I will take your comments into account.
Greetings :-) -
@guy038 said in Macro for Open, Find and Replace and Save:
Hello, @josé-luis-montero-castellanos, @aln-kilborn and all,
@josé-luis-montero-castellanos, regarding your regex S/R :
-
SEARCH
(?s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)
-
REPLACE
?1\5\2\7\4\1\6\3:${12}${9}${14}${11}${8}${13}${10}
Why do you need the leading in-line modifier
(?s)
, in the search part ? Do you mean that the single char.
in group2
,4
,6
,9
,11
and13
may also represent a line-break char (\r
or\n
) ?I suppose not ! Then, your correct search regex is rather :
(?-s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)
where any
.
single char will represent a non-break char, only !
Now, I noticed that the groups used, in replacement, for each alternative of the search regex, are in the same order ! Then, you can use, preferably, a specific feature of the Boost Regex engine, called
Branch Reset
For instance, in your regex, the numbers of each group are :
(?-s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S) Gr : 1 2 3 4 5 6 7 |8 9 10 11 12 13 14
If we use the
Branch Reset
feature the search regex becomes :(?-s)(?|(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)) Gr: 1 2 3 4 5 6 7 |1 2 3 4 5 6 7
Thus, your entire regex S/R can be simplified as below :
-
SEARCH
(?-s)(?|(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S))
-
REPLACE
\5\2\7\4\1\6\3
For instance, given this INPUT text :
<St2/S4<Xt6/X <Xt9/XB<StD/S
You would get the OUTPUT text, below :
<Xt2/X4<St6/S <St9/SB<XtD/X
Notes :
-
The
Regular expression
option must be selected -
Preferably, tick the
[Wrap around](https://www.ahijoy.com/)
option
Best Regards,
guy038
I tried it but didn’t work
-