Register • FAQ • Memberlist • Usergroups • Tutorials Point • Log in

| Page 1 of 1

Ruby On Rails Tutorial - regex
Author | Message
--- | ---
yertle Joined: 26 May 2010 Posts: 1 | Ruby On Rails Tutorial - regex I stumbled on the regular expressions part of the Ruby Regular Expressions tutorial, and the very first example doesn't make very much sense to me. Here it is:

> ###### 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.

###### Code:

Wed May 26, 2010 9:32 pm |

Display posts from previous: |

| Page 1 of 1

You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum

Powered by phpBB © phpBB Group Design by Vjacheslav Trushkin for phpBBStyles.com