From: Ben Giddings Date: 2009-08-21T23:28:03+09:00 Subject: Re: How to convert string "/regexp/i" to /regexp/i - ? On Aug 21, 2009, at 06:04, Joao Silva wrote: > I tried this, but it's totally unsafe way (these strings are > provided by > user). If the strings are provided by an untrusted source, don't use any solution that uses eval(). Instead, use a solution that recognizes the string contains a regexp and then uses a regexp constructor after pulling the relevant data out of the string. Something along the lines of: def parse_input(str) if md = %r{^/(.*)+/(.*)*$}.match(str) #it's a regexp pattern = md[1] if md[2] # deal with the flags flags = deal_with(md[2] end Regexp.new(pattern, flags) else ... end end Ben