From: 7stud -- Date: 2009-08-21T19:10:38+09:00 Subject: Re: [regexp] How to convert string "/regexp/i" to /regexp/i 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? str = "/regexp/i" pieces = str.split("/") pattern = pieces[1] my_regex = Regexp.new(pattern, true) md = my_regex.match("hello ReGexP") puts md[0] --output:-- ReGexP Or, more generally: str = "/reg.*?exp/im" pieces = str.split("/") pattern = pieces[1] flags = pieces[2] arg_two = 0 flags.length.times do |i| case flags[i, 1] when "i" arg_two |= Regexp::IGNORECASE when "m" arg_two |= Regexp::MULTILINE when "x" arg_two |= Regexp::EXTENDED end end regex = Regexp.new(pattern, arg_two) test_str =<