From: Robert Klemme Date: 2009-04-11T06:45:59+09:00 Subject: Re: regex woes with breaklines On 10.04.2009 14:52, Aa Wilson wrote: > Andrew Timberlake wrote: > >> s = "test\r\ntest
\r\ntest\ntest\rtest
\ntest" >> s.gsub(/(?:
)*(?:\r\n|\n|\r)/, "
\n") >> #=> "test
\ntest
\ntest
\ntest
\ntest
\ntest" > > Thanks a million. It feels like a waste replacing something that's > already there, but I suppose that's just my conceptions of real life > getting in the way of my abstractions. Not necessarily: with 1.9's regular expression engine there is negative lookbehind as well. You could use that to prevent substitution of newlines which are preceeded by a
already. http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt > I was actually hoping that '$' (or possibly '$$?') would cover all the > CR/LF/CRLF cases for me, was I mistaken about that? I believe it does not cover \r alone. In every case it is safer to be explicit IMHO. Btw, I believe you can simplify to (?:\r\n?|\n). Kind regards robert