From: Paul Duncan Date: 2003-04-19T02:26:25+09:00 Subject: Re: [Q] Reg. Expressios with "\n" --bpVaumkpfGNUagdU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Eric Schwartz (emschwar@pobox.com) wrote: > "Hal E. Fulton" writes: > > IIRC you can use the multiline modifier "m" on > > the RE. I haven't tried this: > >=20 > > str =3D~ /(.*<\/html>)/m >=20 > But when parsing HTML, you probably shouldn't be using REs at all. > This perfectly legal HTML will confuse that RE: >=20 > > > I agree with the sentiment (that using REs to parse HTML, XML, etc) isn't a good idea, but the example above isn't valid. Greedy matching takes precedence, so it actually works like it should. -- #!/usr/bin/ruby str =3D " test html bleh " puts $1 if str =3D~ /(.*)<\/html>/m -- :!./re_test.rb =20 test html bleh -- Here's a better example: -- #!/usr/bin/ruby str =3D " here's some bold text
here's some more bold text" puts "greedy: #$1" if str =3D~ /(.*)<\/b>/m puts "non-greedy: #$1" if str =3D~ /(.*?)<\/b>/m -- :!./re_test.rb greedy: here's some bold text
here's some more bold text non-greedy: here's some bold text