Hi, @terry-r and All,
In your last post, Terry, the (?|\R|\z) regex syntax is, for instance, a branch reset group structure. However, as it is said here :
If you don’t use any alternation or capturing groups inside the branch reset group, then its special function doesn’t come into play. It then acts as a non-capturing group.
So, I don’t think that, in that specific case, the branch reset group syntax was necessary ;-))
And for everybody, to, clearly, show the difference between a capturing list of alternatives and a branch reset group, let’s consider the two following regexes, which matches, either, one of the 5-chars strings : axyzw, apqrw or atuvw
A) with a list of consecutive alternatives, in a capturing group :(a)(x(y)z|(p(q)r)|(t)u(v))(w)
When the regex matches axyzw, group 1 = a, group 2 = x(y)z, group 3 = y and group 8 = w
When the regex matches apqrw, group 1 = a, group 2 = (p(q)r), group 4 = p(q)r, group 5 = q and group 8 = w
When the regex matches atuvw, group 1 = a, group 2 = (t)u(v), group 6 = t, group 7 = v and group 8 = w
B) with a branch reset group ( NOT a capturing group itself ! ) :
(a)(?|x(y)z|(p(q)r)|(t)u(v))(w)
When the regex matches axyzw, group 1 = a, group 2 = y, group 3 is undefined and group 4 = w
When the regex matches apqrw, group 1 = a, group 2 = p(q)r, group 3 = q and group 4 = w
When the regex matches atuvw, group 1 = a, group 2 = t, group 3 = v and group 4 = w
An other example. Given that text :
abcdefg hijklmn opqrstuThe regex S/R :
SEARCH (abcdefg)|(hijklmn)|(opqrstu)
REPLACE ==\1\2\3== OR, also, ==$0==
would change the text as :
==abcdefg== ==hijklmn== ==opqrstu==Note that, in the syntax ==\1\2\3==, only one group is defined, at a time and the two others are just “empty” groups !
Now, with the same initial text, the regex S/R, below :
SEARCH ab(cde)fg|hi(jkl)mn|op(qrs)tu
REPLACE ==\1\2\3==
gives :
==cde== ==jkl== ==qrs==whereas the following regex S/R, with a branch reset group and only group 1, in replacement :
SEARCH (?|ab(cde)fg|hi(jkl)mn|op(qrs)tu)
REPLACE ==\1==
would produce the same results
…and the regex S/R :
SEARCH (?|ab(cde)fg|hi(jkl)mn|op(qrs)tu)
REPLACE ==\1\1\1==
would give :
==cdecdecde== ==jkljkljkl== ==qrsqrsqrs==Best Regards,
guy038