I am reading the code of a regular expression parser, and start to wonder if the syntax of regular expression is itself regular, and can be expressed with another (quite complicated) regular expression?
rere = "" # the regular expression of regular language
match1 = re.match(rere, "[a-z]+@[a-z]+.com") # True
match2 = re.match(rere, ")az[") # False
I don't see any recursive structure in regular expression syntax, so I think maybe this is doable?
If it is, what does the expression look like? If not, why?
An expression followed by '*' can be repeated any number of times, including zero. An expression followed by '+' can be repeated any number of times, but at least once. An expression followed by '? ' may be repeated zero or one times only.
We are interested in What is Regular Expression that is corresponding to DFA . Certainly, there could be multiple Regular Expressions corresponding to it; we prefer a simpler one.
No, if you use standard regular expressions. The reason is that you cannot satisfy the pumping lemma for regular languages.
A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.
You cannot parse nested parentheses with a regular expression because you would need infinite state to do so. So the answer is no. What you are looking for is called context-free grammars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With