[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Variable substitution in a regex

Scott Pack

5/17/2005 11:24:00 PM

Hi,

I am new to Ruby. Can I substitute the value of a
variable into a regular expression? For example:

exp = /(\d+)/ #works
exp = /(\d+)/ + 'some string value' #Not!

Thanks,

S




__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/...


2 Answers

James Gray

5/17/2005 11:36:00 PM

0

On May 17, 2005, at 6:24 PM, Scott Pack wrote:

> Hi,
>
> I am new to Ruby. Can I substitute the value of a
> variable into a regular expression? For example:
>
> exp = /(\d+)/ #works
> exp = /(\d+)/ + 'some string value' #Not!

Yes, the same way you interpolate in strings:

exp = /(\d+)#{'some string value'}/

Hope that helps.

James Edward Gray II


Nikolai Weibull

5/17/2005 11:46:00 PM

0

Scott Pack wrote:

> I am new to Ruby. Can I substitute the value of a
> variable into a regular expression? For example:
>
> exp = /(\d+)/ #works
> exp = /(\d+)/ + 'some string value' #Not!

exp = /(\d+)#{variable}/

but I donâ??t understand if thatâ??s what you want. Your example doesnâ??t
agree with your question,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}