Regexp match problem

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? Well then UniversityRenter is the place to go for college apartments!"

irb> @joe == @html_code
=> true

irb> @joe.match(@html_code)
=> nil

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
[email protected]

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
[email protected]

Thanks Rob.

I ended up just doing @joe.include?(@html_code), which seems to be
working.