Quantcast
Channel: Is there a difference between a (general) pattern and a string pattern? - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Daniel Huber for Is there a difference between a (general) pattern and a string pattern?

$
0
0

As Domen already pointed out, Pattern and StringExpression differ. Therefore, what you can do, is to use a pattern together with a PatternTest that request a boolean function. As boolean function you choose:

StringMatchQ[#, "A" ~~ ___] &

With this the pattern looks like:

_?(StringMatchQ[#, "A" ~~ ___] &)

Now you approach works:

myList = {"AB", "B", "AABB", "BAA", "ABB"};Position[myList, _?(StringMatchQ[#, "A" ~~ ___] &), {1},Heads -> False]{{1}, {3}, {5}}

Viewing all articles
Browse latest Browse all 3

Trending Articles