How to generate dynamic regexp pattern from strings?

Hi, Could anyone tell me how to generate regexp pattern from strings?

for example, how to code the return_pattern(str) method?
thanks!

str = “^test|production-(\d+)”
return_pattern(str) ===> /^test|production-(\d+)/

def return_pattern(str)
???
end

On Jan 8, 2008, at 11:39 PM, Nanyang Z. wrote:

end

Posted via http://www.ruby-forum.com/.

Regexp.escape string

a @ http://codeforpeople.com/

ara howard wrote:

On Jan 8, 2008, at 11:39 PM, Nanyang Z. wrote:

end

Posted via http://www.ruby-forum.com/.

Regexp.escape string

a @ http://codeforpeople.com/

Thank you!!

On Jan 9, 2008 7:44 AM, ara howard [email protected] wrote:

???
end

Regexp.escape string

Actually, Regexp.compile string or Regexp.new string

Regexp.escape avoids interpretation of special characters.

Eivind.