2

Out of curiousity, is it possible to write a regex, which checks if other regexs are valid.

cmorse
  • 337
  • 1
  • 7
  • 15
lavrton
  • 18,973
  • 4
  • 30
  • 63

1 Answers1

1

No, it is not possible: regular expression execution model is not powerful enough for that.

In order for a regular expression string to be valid, all parentheses in the string must be balanced. Since it is not theoretically possible to write a regular expression to verify if all parentheses in a string are balanced, it is also not possible to write a regular expression to check validity of a regular expression string.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523