From: David Douthitt Date: 2000-05-18T14:45:04-05:00 Subject: [ruby-talk:02897] Funny unexpected match.... This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=_653D7558.5534509E Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Put simply, using "||" as a match expression in gsub matches an empty = line. Say WHAT? I want to match a literal "vertical-bar vertical-bar". Here's the test code: #!/opt/ruby/bin/ruby # ruby 1.4.3 (1999-12-08) [hppa1.1-hpux10.20] test =3D "||" test2 =3D "\|\|" line =3D "" p line.gsub(/#{test}/, "*** ding ding ding ***") p line.gsub(/#{test2}/, "*** dong dong dong ***") To me, this should print nil nil But the output instead is: *** ding ding ding *** *** dong dong dong *** Why? PS: This code came up in a pretty printer I'm writing - not a "reformatter"= but an HTML-based "pretty-printer" which highlights different sections = and so on. If you've read "Code Complete" you've seen something like it. = If you haven't read "Code Complete", YOU SHOULD (as well as any programmers= working for you, or any programmers you work for, or any programmers you = know...... :-) --=_653D7558.5534509E Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Put simply, using "||" as a match expression in gsub = matches=20 an empty line.  Say WHAT?  I want to match a literal "vertical-ba= r=20 vertical-bar".
 
Here's the test code:
 
#!/opt/ruby/bin/ruby
 
# ruby 1.4.3 (1999-12-08) [hppa1.1-hpux10.20]
 
test =3D "||"
test2 =3D "\|\|"
line =3D = ""
 
p line.gsub(/#{test}/, "*** ding ding ding ***")
p= =20 line.gsub(/#{test2}/, "*** dong dong dong ***")
To me, this should print
 
nil
nil
 
But the output instead is:
 
*** ding ding ding ***
*** dong dong dong ***
 
Why?
 
PS: This code came up in a pretty printer I'm writing = - not a=20 "reformatter" but an HTML-based "pretty-printer" which highlights = different=20 sections and so on.  If you've read "Code Complete" you've seen = something=20 like it.  If you haven't read "Code Complete", YOU SHOULD (as well as = any=20 programmers working for you, or any programmers you work for, or any = programmers=20 you know...... :-)
 
 
--=_653D7558.5534509E--