bulky regex
- From: rabbit@xxxxxxxxx (Peter Rabbitson)
- Date: Wed, 27 Apr 2005 12:16:05 -0500
Hello everyone,
This is the first time I was able to get a complex regex actually working as
I expect, but I wanted someone to comment on it, in case I am overlooking
something very major.
I am trying to throw away a certain string out of random text. The
occurences might be as follows:
Free UPS Ground Shipping <rest of string>
<some of string> free ground shipping !! <rest of string>
<some of string> free UPS ground shipping!!!
and all variations of the above. Here is what I did:
description =~ s/ #take away free ground shipping text
(?: #non-capturing block for | inclusion
(^) #start of string
| #or
(?<=\S) #lookbehind non-space character
)
\s* #maybe some spaces
free #word 'free'
\s+ #at least one space
(?:ups\s+)? #non-capturing 'ups' with at least one trailing space
ground #'ground'
\s+ #spaces
shipping #'shipping'
\s* #maybe some spaces
!* #maybe some exclamation marks
\s* #maybe some more spaces
(?: #non-capturing for | inclusion
($) #end of string
| #or
(?=\S\s?) #lookahead non-space character maybe followed by a space (I want to keep the space if I am cutting from inside a string)
)
//ixg; #replace with nothing
Seems to be working, but I am afraid it will bite me later. Appreciate any
comments. The reason I placed all the (?: ) is to speed it up at least a
bit, I remember reading somewhere that it matters.
Thanks
Peter
.
- Follow-Ups:
- Re: bulky regex
- From: Jay Savage
- Re: bulky regex
- From: Peter Rabbitson
- Re: bulky regex
- Prev by Date: Re: REGEXP removing - il- - -b-f and - il- - - - f
- Next by Date: Re: bulky regex
- Previous by thread: keyword expansion script
- Next by thread: Re: bulky regex
- Index(es):