I believe Zalgo has the answer to this, via an equivalent question. https://stackoverflow.com/questions/1732348/regex-match-open...
Perhaps the most epic reply I have ever seen on SO.
Is there a regular expression to detect a valid regular expression?
21–30 of 224 posts
Re: Is there a regular expression to detect a valid regular expression?
#22Earlier quoted context omitted.
Perhaps the most epic reply I have ever seen on SO.
It’s a famous post on StackOverflow, but I don’t find it particularly helpful.
Re: Is there a regular expression to detect a valid regular expression?
#23IIRC, regex can be implemented by an NFA which can't solve balanced parentheses that are part of regex syntax.
One is CS definition of regular expression matcher for regular languages. The other is extension of that into non-regular languages, typically PCRE compatible.
Re: Is there a regular expression to detect a valid regular expression?
#24Earlier quoted context omitted.
It’s a famous post on StackOverflow, but I don’t find it particularly helpful.
I don't think that answer was written with the intent of being particularly helpful, I think it was written with a different goal in mind.
Re: Is there a regular expression to detect a valid regular expression?
#25This immediately triggers the Liar's paradox [1]. Can a regular expression check its own validity? How can you tell if it's lying? Beware of bugs in the above code; I have only proved it correct, not tried it --Donald Knuth [1] https://en.wikipedia.org/wiki/Liar_paradox
Re: Is there a regular expression to detect a valid regular expression?
#26"That's not very enterprisey of you"
Oooh, I'm laughing so hard it hurts. It's been a particularly 'enterprisey' week at work.
Re: Is there a regular expression to detect a valid regular expression?
#27This immediately triggers the Liar's paradox [1]. Can a regular expression check its own validity? How can you tell if it's lying? Beware of bugs in the above code; I have only proved it correct, not tried it --Donald Knuth [1] https://en.wikipedia.org/wiki/Liar_paradox
Re: Is there a regular expression to detect a valid regular expression?
#28Earlier quoted context omitted.
It’s a famous post on StackOverflow, but I don’t find it particularly helpful.
Had it not gotten extremely lucky, it would have a very negative score. Anything intended to be funny on StackOverflow doesn’t go over well very often.
Re: Is there a regular expression to detect a valid regular expression?
#29I believe Zalgo has the answer to this, via an equivalent question. https://stackoverflow.com/questions/1732348/regex-match-open...
> Moderator's Note
> This post is locked to prevent inappropriate edits to its content. The post looks exactly as it is supposed to look - there are no problems with its content. Please do not flag it for our attention.
Re: Is there a regular expression to detect a valid regular expression?
#30This immediately triggers the Liar's paradox [1]. Can a regular expression check its own validity? How can you tell if it's lying? Beware of bugs in the above code; I have only proved it correct, not tried it --Donald Knuth [1] https://en.wikipedia.org/wiki/Liar_paradox
A self-hosted compiler is definitely not a case of the liars paradox, so I don’t think this applies. In fact, it doesn’t matter what the parser is written in, at some point you do have to trust that it actually follows the spec, probably through testing.
FYI. I am just having some philosophical fun with GIGO.
Ultimately, computers are just instruments which amplify human intention, it's not the computers's job to be ultimate moral arbiter of our words.
Gödel's incompleteness theorem already tells us that a system cannot prove its own correctness.