[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

escaping for regexp ???

pere.noel

9/17/2006 7:35:00 AM

i've a regexp like that :

/.*#{name}$/ === path

however the variable "name" could, for example, in the form of :

"L2 Cache (per CPU)"

then, the string "name" might contain reserved chars for regexp,

i plan to escape them replacing "(" by "\\(" etc...

however i wonder if such a function for escaping reserved chars does
exists buit-in ???

notice i don't want to escape ".*" because i plan to use the wild card.


--
une bévue
2 Answers

Paul Lutus

9/17/2006 7:47:00 AM

0

Une bévue wrote:

> i've a regexp like that :
>
> /.*#{name}$/ === path
>
> however the variable "name" could, for example, in the form of :
>
> "L2 Cache (per CPU)"
>
> then, the string "name" might contain reserved chars for regexp,
>
> i plan to escape them replacing "(" by "\\(" etc...
>
> however i wonder if such a function for escaping reserved chars does
> exists buit-in ???

Regexp.escape(name)

--
Paul Lutus
http://www.ara...

pere.noel

9/17/2006 9:35:00 AM

0

Paul Lutus <nospam@nosite.zzz> wrote:

>
> Regexp.escape(name)

fine thanxs !!!
--
une bévue