I have a user-created string which is to be used as a regular expression. How can I test the validity of this string?
My first thought was to use a regular expression to test this, but, thinking about it, the regular expression syntax itself is not a regular language, so this doesn't work.
My second thought was to attempt to create a RegExp object using the string. However, the documentation does not mention what should happen when the string is an invalid regular expression.
Any other ideas?