From: Wayne Blair Date: 2001-06-05T17:05:22+09:00 Subject: [ruby-talk:16227] String#scan strange behavior This is a multi-part message in MIME format. ------=_NextPart_000_021B_01C0ED75.20F00010 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Is this normal? It looks like $& ends up being a hungry match, but not = the String#scan result. irb> a =3D "aaa \"\\\"hello\\\"\"zzz" "aaa \"\\\"hello\\\"\"zzz" irb>regex =3D /"(\\"|[^"])*"/ /"(\\"|[^"])*"/ irb> irb> a.scan(regex) [["\\\""]] # this is strange result - $& is what I = expected in some way in result irb> print $& "\"hello\""nil Wayne Wayne ------=_NextPart_000_021B_01C0ED75.20F00010 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Is this normal?  It looks like = $& ends up=20 being a hungry match, but not the String#scan result.
 
irb> a =3D "aaa=20 \"\\\"hello\\\"\"zzz"
"aaa=20 \"\\\"hello\\\"\"zzz"
irb>regex =3D /"(\\"|[^"])*"/
/"(\\"|[^"])*"/
irb>
irb>=20 a.scan(regex)
[["\\\""]]      &nb= sp;         =20 # this is strange result - $& is what I expected in some way in=20 result
irb> print $&
"\"hello\""nil
 
Wayne
 
Wayne
 
 
------=_NextPart_000_021B_01C0ED75.20F00010--