1

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?

Armin Vollmer
  • 403
  • 3
  • 6
  • 1
    String patterns are not the same thing as patterns. – Kuba Jul 09 '19 at 10:54
  • 1
    Linked topic should answer your question, let me know if that is not the case. – Kuba Jul 09 '19 at 10:56
  • Welcome to Mma.SE. Thanks for taking the [tour]. Be sure you have learning about asking and what's on-topic. 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. – rhermans Jul 09 '19 at 11:03

0 Answers0