My code will receive a parameter containing a string representation of a regular expression. It is probable that the strings would be like "/whatever/" with slashes at the beginning and end. Given a string,
str = "/^foo.*bar$/"
I would like to create a regular expression from that string.
When I do:
pat = Regexp.new(str)
# => /\/^foo.*bar$\//
pat.match "foolishrebar"
# => nil
all of the special characters are quoted. I have not figured out how not to quote the string.
When I create a pattern directly with /pattern/, it works fine.
pat = /^foo.*bar$/
pat.match "foolishrebar"
# => #<MatchData "foolishrebar">
\Aand\z(beginning/ending of string) instead of^and$(beginning/ending of line) in Ruby.eval(str). But I am not posting this as an answer because I know that there are stupid people around who would downvote such an answer as soon as I post one.