From: Matt Harrison Date: 2008-10-26T05:23:43+09:00 Subject: regular expressions and conditionals --4Ckj6UjgE2iN1+kY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I'm writting a little program to convert some source files to html. I'm using regexp's to determine the content of each line and format it accordingly. For example, if the line starts with a #, then it should be output with a div (and id set to 'comment'). The problem is with matching the regular expressions. If I do this: f = File.new("myfile", "r") while !f.eof? line = f.gets if line.match(/^# (.*)/) puts "
#{line.match(/^# (.*)/)[0]}
" end end Then not only do I get the commen lines formatted properly, I also get a "nil" for every other line in the file. How should I be using regexps in conditionals? I'm sure this should be easy but I've googled around for an hour and I can't find what's wrong. TIA Matt --4Ckj6UjgE2iN1+kY Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkkDfi4ACgkQeUAv5ibJHeEf8QCgrifFIgROV9JmyY1n3Fnaj74B NDgAoLU/1LIirM6XVWCkW2XwXgg+hBVR =i5Tl -----END PGP SIGNATURE----- --4Ckj6UjgE2iN1+kY--