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

• To: mathgroup at smc.vnet.net
• Subject: [mg96205] Re: How to get position of string in a mixed list? (string pattern
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Mon, 9 Feb 2009 05:35:07 -0500 (EST)
• References: <gmndli\$s1k\$1@smc.vnet.net>

Hi,

Clear[substringPosition]
substringPosition[lst_List, spatt_] :=
MapIndexed[
If[{} =!= #, {#2[[1]], #1}, {}] & , (substringPosition[#,
spatt] & /@ lst) ] /. {} :> Sequence[]
substringPosition[s_String, spatt_] := StringPosition[s, spatt]
substringPosition[_, _] := {}

and

substringPosition[
{"a", "abc", "dfe", "nab", 1, 2, 3, {1, 2}} ,
___ ~~ "ab" ~~ ___
]

gives

{{2, {{1, 3}}}, {4, {{1, 3}, {2, 3}}}}

Regards
Jens

goodhei8 at gmail.com wrote:
> 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? How to use a string pattern in a list
> pattern? how to use a pattern with a condition (both list pattern&/;
> StringQ[#] and list pattern /;StringQ[]&, no working for me)
>
> Thanks.
>

• Prev by Date: Re: How to get position of string in a mixed list? (string
• Next by Date: Re: I have an operator, How do I DSolve it?
• Previous by thread: Re: How to get position of string in a mixed list? (string pattern
• Next by thread: Stationarity tests - Dickey-Fuller, Phillips-Perron