Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > String#match vs. Regexp#match - confused

Reply
Thread Tools

String#match vs. Regexp#match - confused

 
 
Old Echo
Guest
Posts: n/a
 
      09-04-2008
Hello everyone,
I'm very puzzled by the following:

a = ".*me"
b = /.*me/
test = "dont_ignore.me.fixture"

a.match(test)
=> nil
b.match(test)
=> #<MatchData:0x350fe8>

Huh? When looking through the ri documentation for the "match" method on
the String class, it says it take the contents of the String and
converts it to a regexp before doing a match.

So...how come the two matches do not return the same result? And even
more importantly, how can I make sure that they do?

Thank you,
Sebastian
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Adam Shelly
Guest
Posts: n/a
 
      09-04-2008
On 9/4/08, Old Echo <> wrote:
> Hello everyone,
> I'm very puzzled by the following:
>
> a = ".*me"
> b = /.*me/
> test = "dont_ignore.me.fixture"
>
> a.match(test)
> => nil
> b.match(test)
> => #<MatchData:0x350fe8>
>
> Huh? When looking through the ri documentation for the "match" method on
> the String class, it says it take the contents of the String and
> converts it to a regexp before doing a match.


test.match a
=> #<MatchData:0x283a534>

The argument is converted to a regexp, not the original String.

-Adam

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
confused! Dennis J. Tuchler Firefox 4 05-19-2005 12:04 AM
Thunderbird 1.0 got confused with news 'Captain' Kirk DeHaan Firefox 0 12-24-2004 08:16 PM
Utterly confused - web, sql tables what to use for development? RichGK ASP .Net 1 07-31-2004 05:16 AM
Confused and bewildered. DJ Miller ASP .Net 4 09-04-2003 06:10 PM
Confused. Need Help! Cobra Pilot Perl 1 07-22-2003 03:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57