Re: bulky regex



On Wed, Apr 27, 2005 at 12:16:05PM -0500, Peter Rabbitson wrote:
> 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

Ops. (?=\S\s?) above should be (?=\s\S), if it's not at the end of a
string I am guaranteed at least a single space, sorry about that.
.



Relevant Pages

  • Re: how to replace spaces in a string.
    ... On Fri, 13 May 2005, P-A Caron wrote: ... > I would like to replace "space space" in a string by a single space. ... Prev by Date: ...
    (comp.lang.tcl)
  • Re: A repost - Permuting SPACES within a String of words
    ... Then you should check for empty cells array ... Use ubound to find out how many cells your array contains ... > a) where there is no space between any of the words in the string ... > together and the lone word is separated by a single space. ...
    (microsoft.public.excel.programming)
  • A repost - Permuting SPACES within a String of words
    ... where there is no space between any of the words in the string ... possible permutations. ... Iwentto Paris ... and the lone word is separated by a single space. ...
    (microsoft.public.excel.programming)
  • Re: RegularExpressionValidator expression help
    ... Take a look at first expression ... ("\s" means a single space, and should be used in .NET) ... no way to check by regex if given postal code is related to given ... the string is correct and string has proper format, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Remove spaces in CSV file using VB6
    ... using a Byte array instead of a string unless speed is critical (which I ... I am pretty sure that the OP wants to keep the single space between ...
    (microsoft.public.vb.general.discussion)