Forum: Ruby on Rails REGEXP MATCH PROBLEM

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joe P. (Guest)
on 2007-03-30 18:46
Why doesn't this return true when I do the "match" method?

irb> @html_code = @joe
=> "Are you in college and looking for <a
href='http://www.UniversityRenter.com'
>apartments</a>?  Well then UniversityRenter is the place to go for <a href='htt
p://www.UniversityRenter.com'>college apartments</a>!"

irb> @joe == @html_code
=> true

irb> @joe.match(@html_code)
=> nil
Rob B. (Guest)
on 2007-03-30 20:07
(Received via mailing list)
On Mar 30, 2007, at 10:46 AM, Joe P. wrote:
> => true
>
> irb> @joe.match(@html_code)
> => nil

because the '?' in the string is a metacharacter so when turned into
a Regexp by String#match(pattern), it doesn't match 'itself'

Try @joe.match(Regexp.escape(@html_code))

Or just look at how Regexp.escape(@joe) differs from @joe

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
Joe P. (Guest)
on 2007-03-30 20:12
Rob B. wrote:
> On Mar 30, 2007, at 10:46 AM, Joe P. wrote:
>> => true
>>
>> irb> @joe.match(@html_code)
>> => nil
>
> because the '?' in the string is a metacharacter so when turned into
> a Regexp by String#match(pattern), it doesn't match 'itself'
>
> Try @joe.match(Regexp.escape(@html_code))
>
> Or just look at how Regexp.escape(@joe) differs from @joe
>
> -Rob
>
> Rob B.    http://agileconsultingllc.com
> removed_email_address@domain.invalid

Thanks Rob.

I ended up just doing @joe.include?(@html_code), which seems to be
working.
This topic is locked and can not be replied to.