MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to get position of string in a mixed list? (string pattern in


Hi,

> for list like {"a","abc","dfe","nab",1,2,3,{1,2}}, I want to get all
> strings' position in the list which match a pattern (like
> ___~~"ab"~~___). How to do it?

This is your list:

test = {"a", "abc", "dfe", "nab", 1, 2, 3, {1, 2}}

This does the job:

Position[test, x_String /; StringMatchQ[x, ___ ~~ "ab" ~~ ___]]

or, if you prefer,

Position[test, _String?(StringMatchQ[#, ___ ~~ "ab" ~~ ___] &)]

Regards,
Leonid




  • Prev by Date: NMinimize Bug in Mathematica 7.0?
  • Next by Date: Re: How to get position of string in a mixed list? (string pattern
  • Previous by thread: Re: How to get position of string in a mixed list? (string
  • Next by thread: Re: How to get position of string in a mixed list? (string pattern in