imelody
1
In C/C++ language, can use “//” to comment,such as "//i++ "
I want use ruby to distinguish the comment lines and code lines.
but fail. : (
f.each do|line|
puts line
if line =~ /^////.*/
puts “The line contain //.”
end
end
Error: Unexpected tSTRING_BEG
imelody
2
if line =~ /^////.*/
if line =~ /^///
if line =~ %r{^//}
(note that the .* does nothing in your original regexp, i.e. it can be
removed without changing the behaviour)
imelody
3
understand, thanks you very much!
imelody
4
On Thu, Sep 16, 2010 at 4:22 PM, Brian C. [email protected]
wrote:
if line =~ /^////.*/
if line =~ /^///
if line =~ %r{^//}
(note that the .* does nothing in your original regexp, i.e. it can be
removed without changing the behaviour)
For comment lines it’s probably better to allow for some indentation:
if %r{^\s*//} =~ line
puts “This is a comment: #{line}”
end
Kind regards
robert