Re: How to get position of string in a mixed list? (string pattern in
- To: mathgroup at smc.vnet.net
- Subject: [mg96201] Re: How to get position of string in a mixed list? (string pattern in
- From: lshifr at gmail.com
- Date: Mon, 9 Feb 2009 05:34:23 -0500 (EST)
- References: <gmndli$s1k$1@smc.vnet.net>
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