Live data from Hacker News

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

stackoverflow.com

101–110 of 224 posts

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

#101
post #96

Earlier quoted context omitted.

Indeed. Type 0 Grammars are the most powerful grammars we have. https://en.wikipedia.org/wiki/Chomsky_hierarchy#Type-0_gramm... In this type of grammar Godel's incompleteness theorem is equivalent to the Halting problem.

And which programming language did you have in mind?

All of them.

"Type-0 grammars include all formal grammars. They generate exactly all languages that can be recognized by a Turing machine."

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

#102
post #101

Earlier quoted context omitted.

And which programming language did you have in mind?

All of them. "Type-0 grammars include all formal grammars. They generate exactly all languages that can be recognized by a Turing machine."

I see - you have the complexity relation the wrong way round.

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

#103
post #91

> Is there a regular expression to detect a valid regular expression? No, there is not. For example, parentheses in a regex must be balanced, and (famously) there is no regex to detect balanced parentheses.

It depends on the representation. If the representation is in the FSA format (state, character, state), it becomes nearly trivial.

Very underrated comment. Very good point to give food for thought although I think it is clear that it was meant to be on the usual textual representation using the simplest re language (without extensions).

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

#104
post #101

Earlier quoted context omitted.

All of them. "Type-0 grammars include all formal grammars. They generate exactly all languages that can be recognized by a Turing machine."

I see - you have the complexity relation the wrong way round.

Are you sure you aren't mistaken? :-)

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

#105
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.

it's sad that today the stack overflow majority shares your mindset and an answer like that would drown in downvotes or killed by moderation.

some people like to act super serious all the time like they're playing a sitcom version of what they think adulthood is in a quest to be the most boring person on earth like if that's the goal of human interaction

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

#106
I concur that utilizing Spanish, English, and Spanglish in a similar code is definitely not an upbeat practice. The issue is I'm accustomed to coding in English, however, there were a few rules to pursue, (for example, remarking in Spanish or utilizing certain names for tokens) in the undertaking. Anyway, the fact of the matter was simply to give a thought on the calculation, not to give some full reference code. https://www.sswaterproofing.in

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

#107
post #77

Earlier quoted context omitted.

More precisely, it is arbitrarily deep nested clauses that cannot be parsed, on account of true REs not being able to either use recursion or keep count of how deep they are. https://blogs.msdn.microsoft.com/jaredpar/2008/10/15/regular...

Can regex engines actually process arbitrarily deep nestings themselves though? It seems to me it would start getting computationally expensive very quickly to search for those kinds of regexes, so is 'arbitrarily deep' a practical concern for todays hardware?

Yes, regex engines that are designed to do so run in linear time on the size of the regex (as well as linear time with respect to the length of the input).

One such engine is rust's https://github.com/rust-lang/regex

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

#109
post #71
post #54

Earlier quoted context omitted.

A parser. Specifically, an XHTML parser.

How do you think an XHTML parser is written? In particular, how does an XHTML parser identify tokens like start and end tags?

With a pushdown automaton [1] or something like a linear bounded automaton [2].

[1] https://en.m.wikipedia.org/wiki/Pushdown_automaton

[2] https://en.m.wikipedia.org/wiki/Linear_bounded_automaton

More specifically, a stack lets you keep track of nesting. See an opening tag, push something onto a stack. See a closing tag, pop the stack. If the stack is empty at the end, the tags match.

Parsing XHTML in real life is of course much more complicated than this, but this is the basic idea.

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

#110
post #91

> Is there a regular expression to detect a valid regular expression? No, there is not. For example, parentheses in a regex must be balanced, and (famously) there is no regex to detect balanced parentheses.

It depends on the representation. If the representation is in the FSA format (state, character, state), it becomes nearly trivial.

An analogous problem for this representation would be detecting transitions to undefined states, or ambiguous (duplicate) transitions.
Post reply on HN