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

Is there a difference between a (general) pattern and a string pattern?

$
0
0

I have a list myList that contains several strings. I wish to use Position to find the positions of strings in myList that match the pattern "A" ~~ ___.

The first overload for Position in the documentation is:

Position[expr, pattern]gives a list of the positions at which objects matching pattern appear in expr.

Is there a difference between a (general) pattern and a string pattern? In the following code, why does the first call to Position yield an empty list ({}), while the second call to Position gives the positions of the strings in myList that match "A" ~~ ___?

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

{}

{{1}, {3}, {5}}

Is "A" ~~ ___ not a pattern?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images