Joao Silva wrote:
> When i try to use:
>
>
>>> Regexp.new("/regexp/i")
>>>
> => /\/regexp\/i/
>
> But it's not what i want - i need:
>
> /regexp/i
>
> 
>
> How i can convert this proper way?
>
If that is exactly the kind of string you are expecting, I think you are
stuck with having to use eval.
irb(main):001:0> r = eval("/regexp/i")
=> /regexp/i
irb(main):002:0> r.match("REGEXP")
=> #<MatchData "REGEXP">
If you do not need the options, you could just grab the inner part and
make a regexp out of that:
irb(main):001:0> re = "/som.r.g.x\d+/i"
=> "/som.r.g.xd+/i"
irb(main):002:0> re = "/som.r.g.x\\d+/i".match(/\/(.*)\/[^\/]/)[1]
=> "som.r.g.x\\d+"
irb(main):003:0> /#{re}/.match("someregex1123")
=> #<MatchData "someregex1123">
Not really a great solution, though, as you lose information.
-Justin