Help with Regular Expression

トップ ページ
添付ファイル:
Eメールのメッセージ
+ (text/plain)
このメッセージを削除
このメッセージに返信
著者: David A. Sinck
日付:  
題目: 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