Regexp match problem


#1

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


#2

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


#3

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.