|
Re: How to include a string into a regex comparison?: msg#02363ruby-talk
On Fri, Jul 31, 2009 at 11:25 AM, Iñaki Baz Castillo<ibc@xxxxxxxxx> wrote: > valid_content_type = "application/auth-policy+xml" > received_content_type = "application/auth-policy+xml;charset=ISO-8859-1" > > received_content_type =~ /^application\/auth\-policy\+xml;?/ > => 0 > > received_content_type =~ /^#{received_content_type};?/ > => nil > > How to fix it? Thanks a lot. Try this: irb(main):001:0> valid_content_type = "application/auth-policy+xml" => "application/auth-policy+xml" irb(main):002:0> received_content_type = "application/auth-policy+xml;charset=ISO-8859-1" => "application/auth-policy+xml;charset=ISO-8859-1" irb(main):005:0> re = /^#{Regexp.escape(valid_content_type)};?/ => /^application\/auth\-policy\+xml;?/ irb(main):006:0> received_content_type =~ re => 0 Hope this helps, Jesus.
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |