From: "Ara.T.Howard" Date: 2005-09-14T03:47:23+09:00 Subject: Re: Surprising Regexp Behavior On Wed, 14 Sep 2005, 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 > => "" > > Can anyone explain to me how that isn't a bug? irb(main):001:0> html = "

one

\n\n

two

" => "

one

\n\n

two

" irb(main):002:0> html[ %r|

.*? |x ] => "

" irb(main):003:0> html[ %r|

.*?

|x ] => "

one

" irb(main):004:0> html[ %r|

.*?

.* |x ] => "

one

" hmm? but if we use 'm' to make '.' match newline: irb(main):005:0> html[ %r|

.*?

.* |xm ] => "

one

\n\n

two

" alternatively we can name newline explicitly: irb(main):006:0> html[ %r|

.*?

[.\n]* |x ] => "

one

\n\n" probably 'm' is better for html though. irb(main):007:0> html =~ %r|

(.*?)

(.*) |xm and p [$1, $2] ["one", "\n\n

two

"] cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================