From david at interface.co.uk Wed Jun 23 14:50:04 2010 From: david at interface.co.uk (David Johnson-Davies) Date: Wed, 23 Jun 2010 15:50:04 +0100 Subject: [cl-ppcre-devel] Prioritising matches by the order of the alternatives. Message-ID: Is it possible to prioritise matches by the order of the alternatives? This demonstrates what I want to do: (cl-ppcre::scan-to-strings "super(man|dog|girl|woman|boy)" "this is the story of superboy and superman.") This matches "superboy" because it matches the first "super" and then tries each of the ORs until it finds "boy". What I want it to do is match according to the priority I've specified in the OR list. For example, if it finds a "superman" anywhere in the target-string it should match that before trying "superdog" etc. I know I could do this with a bit of Lisp code, but if it's possible to keep it all in the regexp I'd prefer to do that. Thanks, David Johnson-Davies From edi at agharta.de Wed Jun 23 15:18:18 2010 From: edi at agharta.de (Edi Weitz) Date: Wed, 23 Jun 2010 17:18:18 +0200 Subject: [cl-ppcre-devel] Prioritising matches by the order of the alternatives. In-Reply-To: References: Message-ID: Possible, but probably extremely inefficient. Here's an idea: CL-USER 3 > (ppcre:scan-to-strings "dog|man" "a man and his dog") "man" #() CL-USER 4 > (ppcre:scan-to-strings "dog|man(?!.*dog)" "a man and his dog") "dog" #() Edi. On Wed, Jun 23, 2010 at 4:50 PM, David Johnson-Davies wrote: > Is it possible to prioritise matches by the order of the alternatives? > > This demonstrates what I want to do: > > (cl-ppcre::scan-to-strings "super(man|dog|girl|woman|boy)" "this is the story of superboy and superman.") > > This matches "superboy" because it matches the first "super" and then tries each of the ORs until it finds "boy". > > What I want it to do is match according to the priority I've specified in the OR list. For example, if it finds a "superman" anywhere in the target-string it should match that before trying "superdog" etc. > > I know I could do this with a bit of Lisp code, but if it's possible to keep it all in the regexp I'd prefer to do that. > > Thanks, > David Johnson-Davies > _______________________________________________ > cl-ppcre-devel site list > cl-ppcre-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-ppcre-devel > >