Why when trying to find whether one (out of several) patterns matches an expression - using StringMatchQ
- all of them seem to be ignored and no matches are found?
In this simple example I try to find out whether or not the 4-letter-long string "abcd"
starts with an "a"
StringMatchQ[
StartOfString ~~ "a" ~~ _ ~~ _ ~~ _]["abcd"]
True
However, when I try to test whether it starts with either an "a" or, say, a "b",
StringMatchQ[
StartOfString ~~ "a" ~~ _ ~~ _ ~~ _|StartOfString ~~ "b" ~~ _ ~~ _ ~~ _]["abcd"]
False
Shouldn't it be true since the first of the two patterns is a match? Isn't this used to specify that either one pattern or the other is the pattern to be matched?
StringMatchQ["a*" | "b*"]["abcd"]
$\endgroup$