Improve security of regexes to satisfy Rails 4.