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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to