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=''http://www.UniversityRenter.com''>college apartments</a>!" irb> @joe == @html_code => true irb> @joe.match(@html_code) => nil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 30, 2007, at 10:46 AM, Joe Peck wrote:> 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) > => nilbecause 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn wrote:> On Mar 30, 2007, at 10:46 AM, Joe Peck 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 Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.orgThanks Rob. I ended up just doing @joe.include?(@html_code), which seems to be working. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---