MathGroup Archive 2005

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

Search the Archive

Re: refering to a long pattern by a variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57780] Re: refering to a long pattern by a variable
  • From: marloo3 at mail15.com
  • Date: Wed, 8 Jun 2005 03:21:28 -0400 (EDT)
  • References: <200506060821.EAA12505@smc.vnet.net><d83emv$o84$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

thanks all for the responses,
 the following lines will use the idea of yehuda to make the program
manipulate a string with arbitrary length:

txt = "abscbacabzszcazba";
patternletters = Characters["absa"];
pat = Flatten[
    Insert[Characters[patternletters], BlankNullSequence[],
      Partition[Table[i, {i, 2, Length[patternletters]}], 1]]];
StringCases[txt, ShortestMatch[StringExpression @@ pat], Overlaps ->
False]

Out[]={abscba, abzszczba}

other ideas are welcome.
thanks

>yehuda ben-shimol wrote:
> Hi
> First you need to recognize that the full form of ___  is
> BlankNullSequence[].
> The ~~ operator is StingExpression[]
> generate a function (not a clever one, but it will demonstrate the
> idea and easily can be modified)
> makePat[s_String]:=StringExpression @@ (Insert[Characters[s],
> BlankNullSequence[], 2])
> then
>
> txt="abcbacabzzcz";
> StringCases[txt, ShortestMatch[makePat["bc"]], Overlaps -> False]
> will return the answer you need. You can call makePat with any string
> you need (of two characters).
> yehuda

> On 6/6/05, marloo3 at mail15.com <marloo3 at mail15.com> wrote:
> > hello
> > i wish if i could refer to a long pattren by just a variable,
> > suppose the:
> > txt="abcbacabzzcz";
> > and the pattern to search is "b"~~___~~"c"
> > StringCases[txt, ShortestMatch["b" ~~ ___ ~~ "c"], Overlaps -> False]
> > Out[]={bc, bac, bzzc}
> > ok, i hope there is a way to supply just the :
> > pat=Characters["bc"];
> > and some procedure will make the "b" ~~ ___ ~~ "c" from the above pat variable
> > and assign this pattern to pat2 variable so we just write:
> > StringCases[txt,
> > ShortestMatch[pat2], Overlaps -> False]
> > to give the output
> > Out[]={bc, bac, bzzc}
> > i have tried it by StringJoin but it does not work.
> > thanks
> > 
> > 
> >


  • Prev by Date: Re: Function Fit to 3D data set
  • Next by Date: Re: adding text to a plot erases plot?
  • Previous by thread: Re: refering to a long pattern by a variable
  • Next by thread: Re: refering to a long pattern by a variable