From: Kingsley Date: 2003-05-29T22:16:41+09:00 Subject: getting a variable into regexp problems This is a multi-part message in MIME format. ------=_NextPart_000_0003_01C325DF.AF29E900 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hiya How do I get a variable into a regexp? In version 1.6.8 I could do it - but version 1.8 complains about using an explicit regexp: var = "apple" array = %w(pineapple, hamapple, cheese, dog, cat, apple) array.each do |x| if x =~ var then puts x end end I have tried doing if x =~ /var/ and =~ /#{var}/ but that doesnt work :( Any ideas? Thanks Kingsley ------=_NextPart_000_0003_01C325DF.AF29E900 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hiya

 

How do I get a variable into a regexp?

 

In version 1.6.8 I could do it - but version 1.8 complains about = using an explicit regexp:

 

var =3D "apple"

array =3D %w(pineapple, = hamapple, cheese, dog, cat, apple)

 

array.each do |x|

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if x =3D~ var then puts = x

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 end

end

 

I have tried doing if x =3D~ /var/ = and =3D~ /#{var}/ but that doesnt work :(

 

Any = ideas?

 

Thanks

Kingsley

------=_NextPart_000_0003_01C325DF.AF29E900--