Help with Regular Expression

Michael Knee plug-discuss@lists.plug.phoenix.az.us
Wed, 4 Dec 2002 14:33:15 -0700


How about this:

#  first protect your double-newlines by changing them
# to something else
s/\n\n/newline_protector/ ;
# then substitute newlines with spaces
s/\n\r/ / ;
s/\n/ / ;
# finally, replace the double-newlines
s/newline_protector/\n\n/ ;
----- Original Message -----
From: "David A. Sinck" <plug-discuss@grueslayer.com>
To: <plug-discuss@lists.plug.phoenix.az.us>
Sent: Wednesday, December 04, 2002 7:54 AM
Subject: Re: Help with Regular Expression


>
>
> \_ SMTP quoth AZ Pete on 12/3/2002 22:41 as having spake thusly:
> \_
> \_ Unfortunately, the regex David provided didn't quite solve the problem.
> \_ I'll explain via an example.
> \_ If the phrase in question is: hello\nthere
> \_
> \_ The regex s/[^\n][\n][^\n]/ /g; would result in: hell here
> \_ Not only does the newline get removed but one character on either side
of
> \_ it as well.
>
> Doh.  Sorry.   Wait.  I maent to do that.  The shoot yourself in the
> foot thing Friedl talks about.  :-)
>
> \_ This is what I found works:
> \_ s/([^\n])\n([^\n])/\1 \2/
>
> It'd be more proper to say s/.../$1 $2/; \1 and \2 are back references
> typically only used in the match part of a RE and disfavored in the
> replacement.
>
> David
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change  you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss