MathGroup Archive 2002

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

Search the Archive

Re: Re: Pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34008] Re: Re: Pattern matching
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 26 Apr 2002 03:27:33 -0400 (EDT)
  • References: <aa8acl$ha4$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

 > why can't I highlight @@@, press F1, and get information on it?

Yes that would be helpful.
Failing it, here are two suggestions.

1. If you have an expression using the notation then find its full form (or,
maybe, its input form).

Here we have to use HoldForm to stop the expression evaluating

    HoldForm[FullForm[StringJoin@@@cas]]

        Apply[StringJoin,cas,List[1]]

    HoldForm[InputForm[StringJoin@@@cas]]

        Apply[StringJoin, cas, {1}]

2. These short forms are called "operators". Look up Operator in the Help
Browser with scope Mas
You will eventually find yourself at A.2.7 in the Book. This gives all the
oerators.

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"DrBob" <majort at cox-internet.com> wrote in message
news:aa8acl$ha4$1 at smc.vnet.net...
> I love this solution, but it brings up an issue for Wolfram: why can't I
> highlight @@@, press F1, and get information on it?  I found the meaning
> of it, but it was a haphazard search.
>
> Bobby Treat
>
> -----Original Message-----
> From: Allan Hayes [mailto:hay at haystack.demon.co.uk]
To: mathgroup at smc.vnet.net
> Subject: [mg34008]  Re: Pattern matching
>
> John,
>
> listData={"18K0F3C--" , "2K40GXX--" , "400HGXX--" , "5M00G1F--" ,
>       "960KG1D--"};
>
> char=Characters/@listData
>
> cas2= Cases[char, {_,_,_,"H"|"K",__}]
>
> {{4,0,0,H,G,X,X,-,-},{9,6,0,K,G,1,D,-,-}}
>
> StringJoin@@@cas
>
> {400HGXX--,960KG1D--}
>
> --
> Allan
>
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
>
>
> "John Leary" <leary at paradise.net.nz> wrote in message
> news:aa3fq4$7tv$1 at smc.vnet.net...
> > Greetings
> >
> > Can you help me please - there must be a simple solution to this
> problem,
> > but I can't find it.
> >
> >  From a list of character strings and a list of templates,  I need to
> > produce a list of all strings that match any of the templates.  For
> example:
> >
> > listData={"18K0F3C--" , "2K40GXX--" , "400HGXX--" , "5M00G1F--" ,
> "960KG1D--"}
> > listTemplates={"???H?????" , "???K?????"}
> > result={"400HGXX--","960KG1D--"}
> >
> > In the templates, ? is a wild-card that represents a single character.
> > The data strings contain only alpha-numeric characters and hyphens -
> no
> > other characters.
> > There are no special requirements for the result:  duplication and
> random
> > order are acceptable.
> >
> >
> > I searched the MathGroup archive and found a very useful function that
> does
> > exactly what I want, but it works only on individual strings, not
> lists of
> > strings (msg00051):
> >
> > QMMatchQ[s_String, p_String] := MatchQ[Characters[s], Characters[p] /.
> "?"
> > -> _ ]
> >
> >
> >
> > I tried to use it in the following way, but the result is a list of
> the
> > matching templates, not the matching strings :
> >
> > QMMatchQ[s_String, p_String] := MatchQ[Characters[s], Characters[p] /.
> "?"
> > -> _ ]
> > SetOptions[Intersection, SameTest -> (QMMatchQ[#1,#2]& )];
> > result=Intersection[listData,listTemplates]
> > {"???H?????","???K?????"}
> >
> >
> > It ought to be a small step from there to the result that I need, but
> I
> > can't find a simple solution.
> >
> > One alternative approach would be a Do loop:
> >
> > b={};
> >
> Do[b=Append[b,Select[listData,QMMatchQ[#,listTemplates[[n]]]&]],{n,1,Len
> gth[
> listTemplates]}]
> >
> > This works but seems to be very slow for large lists.  In the real
> case,
> > listData can be very large - up to 250,000 elements - and the Do loop
> > approach doesn't seem to be optimum.
> >
> >
> > I would be very grateful for your help.
> >
> >
> > Regards
> >
> > John Leary
> >
> >
> >
>
>
>
>
>
>




  • Prev by Date: Re: Re: Bug in NSolve?
  • Next by Date: Plot3D?
  • Previous by thread: Re: Pattern matching
  • Next by thread: DSolve solution validation