From: "Jesús Gabriel y Galán" Date: 2009-07-31T18:45:23+09:00 Subject: Re: How to include a string into a regex comparison? On Fri, Jul 31, 2009 at 11:25 AM, Iñaki Baz Castillo 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.