If I have a substring (or \'subpattern\') of another string or pattern in a regex alternation, like so:
r\'abcd|bc\'
What is the expected behav
No backtracking takes place at all. Your pattern matches two different types of strings; |
means or. Each pattern is tried out at each position.
So when the expression finds abcd
at the start of your input, that text matches your pattern just fine, it fits the abcd
part of the (bc
or abcd
) pattern you gave it.
Ordering of the alternative parts doesn't play here, as far as the regular expression engine is concerned, abcd|bc
is the same thing as bc|abcd
. abcd
is not disregarded just because bc
might match later on in the string.