escaping for regexp ???

Discussion in 'Ruby' started by Une bévue, Sep 17, 2006.

  1. Une bévue

    Une bévue Guest

    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
    Une bévue, Sep 17, 2006
    #1
    1. Advertising

  2. Une bévue

    Une bévue Guest

    Paul Lutus <> wrote:

    >
    > Regexp.escape(name)


    fine thanxs !!!
    --
    une bévue
    Une bévue, Sep 17, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Hurrell
    Replies:
    4
    Views:
    159
    James Edward Gray II
    Feb 14, 2007
  2. Phlip
    Replies:
    3
    Views:
    151
    Tim Pease
    Aug 17, 2007
  3. Mikel Lindsaar
    Replies:
    0
    Views:
    483
    Mikel Lindsaar
    Mar 31, 2008
  4. Joao Silva
    Replies:
    16
    Views:
    359
    7stud --
    Aug 21, 2009
  5. Jane Doe
    Replies:
    3
    Views:
    136
    Jane Doe
    Sep 13, 2003
Loading...

Share This Page