[thelist] Regex help

Anthony Baratta anthony at baratta.com
Thu May 3 13:44:06 CDT 2007


Tab...

Try this:

(?<=START)(?:(?!START).)*(?=END)

>From a RegEx Expert friend of mine.

-----Original message-----
From: "Tab Alleman" talleman at Lumpsum.com
Date: Thu, 03 May 2007 06:29:09 -0700
To: thelist at lists.evolt.org
Subject: Re: [thelist] Regex help

> That's so simple it just might work.   : )   For now, I've put together a kludge that might work (there's a single character that seems to only come after an END in my source string), but before I go to production I may put a solution like this in place.  Thanks!
> 
> > -----Original Message-----
> > From: thelist-bounces at lists.evolt.org
> > [mailto:thelist-bounces at lists.evolt.org]On Behalf Of Lee Kowalkowski
> > Sent: Thursday, May 03, 2007 6:10 AM
> > To: thelist at lists.evolt.org
> > Subject: Re: [thelist] Regex help
> > 
> > 
> > On 02/05/07, Tab Alleman <talleman at lumpsum.com> wrote:
> > > Except I was overly subtle in describing my string.  The 
> > string begins and ends with any combination of characters 
> > which could include START, so there might be more than two 
> > START's in the string.  I really need to specifcally grab 
> > instances of START that are followed by END before another START.
> > 
> > Phew, firstly I'm not sure what regEx syntax/flavour you want, but I
> > don't think ^ outside of [] will work as it means the beginning of
> > input.  Perhaps ! does it, (I think it does for mod_rewrite).
> > 
> > Your problem is one I have seen many times, and have not been able to
> > solve in a single regEx.  I tend to go for a serial regEx approach,
> > something like:
> > 
> > 1. replace all START with \nSTART and END with END\n.
> > 2. do global search for START(.*)END - works because '.' means
> > anything but the newline character.  Only need the brackets if you're
> > backreferencing without the START and END.  A global search should
> > return an array, so if you want the second instance, it will be the
> > second element of the array.
> > 
> > Fine for searching, if doing search/replace, you'll perhaps need:
> > 
> > 3. replace all \nSTART with START and END\n with END.
> > 
> > If your source string already contains new lines and START and END can
> > be on different lines, you'll need to start with a replace all \n with
> > \x01 (or other character or combination of characters that you're
> > confident won't be present).  And swap the new lines back in
> > afterwards.
> > 
> > That's what I tend to do anyway...
> > 
> > -- 
> > Lee
> > -- 
> > 
> > * * Please support the community that supports you.  * *
> > http://evolt.org/help_support_evolt/
> > 
> > For unsubscribe and other options, including the Tip Harvester 
> > and archives of thelist go to: http://lists.evolt.org 
> > Workers of the Web, evolt ! 
> > 
> -- 
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester 
> and archives of thelist go to: http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 



More information about the thelist mailing list