Can regex be parsed with regex?

I am reading the regular expression analyzer code and starting to wonder if the regular expression syntax is regular and can be expressed by another (rather complicated) regular expression?

rere = "" # the regular expression of regular language match1 = re.match(rere, "[az] +@ [az]+.com") # True match2 = re.match(rere, ")az[") # False 

I donโ€™t see a recursive structure in the syntax of regular expressions, so I think that maybe this is doable?

If so, what is the expression? If not, why?

+7
regex parsing regular-language
source share
1 answer

You cannot parse nested parentheses with a regex because you need an infinite state to do this. So the answer is no. What you are looking for is called context-free grammars .

+3
source share

All Articles