Regexp that matches valid regexps

前端 未结 7 1187
北荒
北荒 2020-12-03 02:38

Is there a regular expression that matches valid regular expressions?

(I know there are several flavors of regexps. One would do.)

7条回答
  •  余生分开走
    2020-12-03 03:26

    As already said, you cannot describe regular expressions with a regular expression due to their recursive nature. You'll need a context free grammar for that.

    But what would be the point of having such a regular expression, anyway? If you just want to check whether a regular expression is correct, you can simply try to use it (Pattern.compile(regexp) in Java) and if it screams it is not valid.

提交回复
热议问题