Quote:
Example:
#!/usr/bin/ruby
line1 = "Cats are smarter than dogs";
line2 = "Dogs also like meat";
Code:
if ( line1 =~ /Cats(.*)/ )
puts "Line1 starts with Cats"
end
if ( line2 =~ /Cats(.*)/ )
puts "Line2 starts with Dogs"
end
This will produce following result:
Line starts with Cats
First of all there's no way that I see to print "Line starts with Cats" - it should be "Line1 starts with Cats"
Second of all, it should be printing "Line2 starts with Dogs" - because line2 =~ /Cats(.*)/
What am I missing? I'm hoping I'm in fact understanding how regular expressions work and that the example has some issues. It's confusing for the first example to potentially be wrong though... Any help would be appreciated, thanks.