How to validate whether a string is a valid regular expression using JavaScript?

  javascript, regex

I have a form input where a user can input a regular expression. This is sent off to an api, but before I do that I need to make sure that the string is valid regular expression syntax. I don’t need to confirm that it’ll match on a specific string, just that it is in-fact valid regex.

My searched are coming up short and I’m not sure how to approach this.

Source: Ask Javascript Questions

LEAVE A COMMENT