Regex to match blank line and comments in a file
How do I ignore comments or blank/empty lines in a file when reading? I
thought /^[\s#]*$/ would do the job but it didn't:
irb(main):180:0> open(inFile, 'r').each { |ln| puts ln if ln !~ /^[\s#]*$/ }
....
....
# and ..... ThIs Is A cOmMeNt .....
....
....
=> #<File:/tmp/running-instances.txt>
irb(main):181:0>
What am I missing here? Any help would be highly appreciated. Cheers!!
PS.
I can do the separately in two steps though:
open(inFile, 'r').each { |ln| next if ln =~ /^\s*$/; puts ln if ln !~
/#[^#]*$/ }
No comments:
Post a Comment