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 = "<p>one</p>\n\n<p>two</p>" > => "<p>one</p>\n\n<p>two</p>" > irb(main):002:0> html.sub!(/<p>(.*?)<\/p>(.*)/) { $1.strip } > => "one\n\n<p>two</p>" > 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? That way you make the regexp engine match more than you need and if you change sub! to gsub! at some time, you'll likely still have only one replacement, because .* matches anything to the end. Kind regards robert