1
$\begingroup$

I want to count all NumberStrings in a list:

In[1]:= myList = {"123", "456", "789", "ab1", "cd2", "xyz"}; 

but, surprising (to me), I have to take a detour here:

In[2]:= Count[myList, NumberString] Out[2]= 0 

by using this explicit pattern specification:

In[3]:= Count[myList, _?(StringMatchQ[#, NumberString]&)] Out[3]= 3 

Any comments?

$\endgroup$
3
  • 1
    $\begingroup$ String patterns are not the same thing as patterns. $\endgroup$ Commented Jul 9, 2019 at 10:54
  • 1
    $\begingroup$ Linked topic should answer your question, let me know if that is not the case. $\endgroup$ Commented Jul 9, 2019 at 10:56
  • $\begingroup$ Welcome! Start with the tour, How to Ask, and the help center. Always edit if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$ Commented Jul 9, 2019 at 11:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.