Help with Regular Expression

David A. Sinck plug-discuss@lists.plug.phoenix.az.us
Wed, 4 Dec 2002 07:54:17 -0700


\_ 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