Live data from Hacker News

Is there a regular expression to detect a valid regular expression?

stackoverflow.com

21–30 of 224 posts

Re: Is there a regular expression to detect a valid regular expression?

#21
post #2

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.

Wow it looks like It was designed by David Carson.

Re: Is there a regular expression to detect a valid regular expression?

#22
post #17

Earlier 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.

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?

#23
post #4

IIRC, regex can be implemented by an NFA which can't solve balanced parentheses that are part of regex syntax.

Regex has two different meaning depending on the context.

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?

#24
post #19
post #17

Earlier 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.

It is helpful in that almost koan way though.

Re: Is there a regular expression to detect a valid regular expression?

#25
post #18

This 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.

Re: Is there a regular expression to detect a valid regular expression?

#27
post #18

This 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

That does not really apply. A compiler can compile itself, it can check if its own code is valid.

Re: Is there a regular expression to detect a valid regular expression?

#28
post #22
post #17

Earlier 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.

The answer was made in '09. StackOverflow was more accepting of some humour at the time. And it is making a valid point: regex isn't the right tool for this job.

Re: Is there a regular expression to detect a valid regular expression?

#29
post #2

I believe Zalgo has the answer to this, via an equivalent question. https://stackoverflow.com/questions/1732348/regex-match-open...

My favorite part of it is the moderators' note at the end:

> 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?

#30
post #25
post #18

This 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.

So what you have to trust is that the spec doesn't produce lies ? ;)

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.

Post reply on HN