When using the same name for part of patterns inside Alternatives how come it behaves differently for strings than in normal patterns?
{StringMatchQ["ab", (x_ ~~ "c") | ("a" ~~ x_)],
StringMatchQ["ab", ("a" ~~ x_) | (x_ ~~ "c")]}
(* False, True *)
{MatchQ[{1, 2}, {x_, 3} | {1, x_}],
MatchQ[{1, 2}, {1, x_} | {x_, 3}]}
(* True, True *)
StringMatchQ["ab", (x_ ~~ "c") | (x_ ~~ "b")]
(* False *)
{StringMatchQ["ab", (x_ ~~ "c") | ("a" ~~ y_)], StringMatchQ["ab", ("a" ~~ x_) | (y_ ~~ "c")]}instead $\endgroup$StringMatchQ["ab", (x_ ~~ "c") | (x_ ~~ "b")]if x was bound to "a" then it would still match on the second one $\endgroup$FullForm@StringReplace["ab", Alternatives[(x_ ~~ "c"), ("a" ~~ y_)] :> 2 x]$\endgroup$