Is it possible to write a regular expression which matches regular expressions? Does anyone have examples? If there is some theoretical obstruction, does anyone know of a regex which will match at least the most common regex patterns?
Is it possible to write a regular expression which matches regular expressions? Does anyone
Share
Regular expressions are not a regular language, and thus cannot be described by a regular expression!
Update: More useful practical answer
You cannot detect valid regular expressions using any regular expression. To detect its validity, you should just parse the string using the regex library and it would fail if it is an invalid regular expression. For example, in Java, it would be something like:
This technique should work with almost any language.