I can''t figure out why this regexp isn''t working in my rails method. I''ve been testing it with the the firefox regular expression tester add on and it works there but not in the rails app. My expression is: /\Q[img[''\E/ I''m trying to match: [img['' I am getting an error saying "Early end to regexp" or something like that -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 15, 2011, at 10:12 PM, Keith Raymond wrote:> I can''t figure out why this regexp isn''t working in my rails method. > I''ve been testing it with the the firefox regular expression tester > add > on and it works there but not in the rails app. > > My expression is: /\Q[img[''\E/ > I''m trying to match: [img[''irb> /\[img\[''/ =~ "[img[''" => 0 You need to ecsape the [ characters as they introduce a character set, e.g., [a-z] or [0-9] or even [img] to match any of ''i'', ''m'', or ''g''.> > I am getting an error saying "Early end to regexp" or something like > that >-Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 16 February 2011 03:41, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > On Feb 15, 2011, at 10:12 PM, Keith Raymond wrote: > >> I can''t figure out why this regexp isn''t working in my rails method. >> I''ve been testing it with the the firefox regular expression tester add >> on and it works there but not in the rails app. >> >> My expression is: /\Q[img[''\E/ >> I''m trying to match: [img['' > > irb> /\[img\[''/ =~ "[img[''" > => 0 > > You need to ecsape the [ characters as they introduce a character set, e.g., > [a-z] or [0-9] or even [img] to match any of ''i'', ''m'', or ''g''.It have noticed previously that some regexp engines are clever enough to work out that a mismatched [ does not need to be escaped, which is likely why it appeared to work in FF. I would have thought though that something that purports to be a ''tester'' should enforce the rules rigorously. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.