From: Robert Klemme Date: 2005-09-14T22:21:34+09:00 Subject: Re: Surprising Regexp Behavior James Edward Gray II wrote: > On Sep 14, 2005, at 6:26 AM, Robert Klemme wrote: > >> James Edward Gray II wrote: >> >>> I keep running into some surprising points with Ruby's Regexp engine >>> today and this first one just looks plain wrong to me: >>> >>> irb(main):001:0> html = "

one

\n\n

two

" >>> => "

one

\n\n

two

" >>> irb(main):002:0> html.sub!(/

(.*?)<\/p>(.*)/) { $1.strip } >>> => "one\n\n

two

" >>> irb(main):003:0> $2 >>> => "" >>> >> >> Maybe I overlooked something but I didn't see anybody mention it: the >> trailing (.*) seems quite superfluous to me. Why did you put it >> there? > > So I could check to see if there was more content after the first > paragraph that I trimmed. The code goes on to replace it with an > ellipses if there was. Ah! In that case I'd something like: html.sub!(/(

)(.*?)(<\/p>)(.*)/) { $1 << $2.strip << $3 } html.sub!(/

(.*?)<\/p>(.*)/) { "

#{$1.strip}

" } Kind regards robert