News for hackers. Stuff that matters.
Re:Stackoverflow, HTML by Regex, topmost answer by jgrahamc on Monday July 05, 2010 @08:26AM (#1488050)
First: please don't editorialize in the title. The "Got to see this" smacks of other places I will not mention.

Second: this is not at all interesting. The person asks a sensible question and then gets some ridiculous replies.

Third: it made me remember my spat with ESR about HTML parsing: http://news.ycombinator.com/item?id=923775 and now I feel sad.

Re:Stackoverflow, HTML by Regex, topmost answer by pclark on Monday July 05, 2010 @09:56AM (#1488192)
I really dislike all this arm chair moderation of hacker news, I like the occasional commentary in submission titles, and I also like the fact the community decides what is or isn't interesting. Like the ~60 people who found this article interesting.
Re:Stackoverflow, HTML by Regex, topmost answer by jgrahamc on Monday July 05, 2010 @10:02AM (#1488199)
The trouble is "Got to see this" is purely the judgement of the submitter and not of the community. The 60 upvotes are the community judgement.
Re:Stackoverflow, HTML by Regex, topmost answer by CodeMage on Monday July 05, 2010 @11:33AM (#1488412)
The trouble is "Got to see this" is purely the judgement of the submitter

Yes, just like "Second: this is not at all interesting" is your judgment in your comment. I know we all want to keep HN different from reddit, but a little tolerance is good.

Re:Stackoverflow, HTML by Regex, topmost answer by Groxx on Monday July 05, 2010 @11:15AM (#1488358)
... on the content, not the title.
Re:Stackoverflow, HTML by Regex, topmost answer by euroclydon on Monday July 05, 2010 @07:36AM (#1487975)
Some person explained that HTML is a Chomsky type 2 grammar and regular expressions are a Chomsky type 3 grammar, and provided this link: http://en.wikipedia.org/wiki/Chomsky_hierarchy

Can anyone here provide a link that makes the discussion of these typed grammars available to laymen?

Re:Stackoverflow, HTML by Regex, topmost answer by bad_user on Monday July 05, 2010 @10:25AM (#1488244)
Oh, I don't know if reducing the grammars to Chomsky is really necessary.

Regular expressions, in their original version, are equivalent to Finite-stage Machines (i.e. ... regular grammars, no recursion, no stack, no memory further than keeping the current state). You can't describe the rules of HTML with a FSM.

Perl's regular expressions contain various enhancements. Newer versions of Perl's regexes also contain direct support for recursion (but frankly, you can't call those "regular expressions" anymore).

So ... if your regex library has recursion support, then you can parse HTML (since with recursion you can parse context-free / Chomsky type-2 grammars). If it doesn't support recursion, then you can't.

Btw ... the equivalent for a context-free grammar would be a Push-down Automaton ... http://en.wikipedia.org/wiki/Pushdown_automaton , which is a FSM + a stack.

Re:Stackoverflow, HTML by Regex, topmost answer by steveklabnik on Monday July 05, 2010 @08:06AM (#1488021)
This answer on Reddit is pretty solid: http://www.reddit.com/r/programming/comments/cm02a/you_cant_...

Depends on your definition of 'laymen,' I guess.

Also note that PCREs actually are recursively enumerable (I think).

Re:Stackoverflow, HTML by Regex, topmost answer by friism on Monday July 05, 2010 @06:10AM (#1487858)
For more discussion (of a blog-post about the answer by Atwood), see here: http://news.ycombinator.com/item?id=944673
Re:Stackoverflow, HTML by Regex, topmost answer by man1sh on Monday July 05, 2010 @07:12AM (#1487937)
I think this is pretty old and has been discussed everywhere many times. Check the date of the question/answer too.
Re:Stackoverflow, HTML by Regex, topmost answer by albertzeyer on Monday July 05, 2010 @08:51AM (#1488092)
Ehm, I wonder a bit, the discussions always goes that HTML is not regular. The poster though asked to just match any open tags. The language of HTML tags clearly is regular, isn't it?
Re:Stackoverflow, HTML by Regex, topmost answer by jauco on Monday July 05, 2010 @11:42AM (#1488435)
For one thing: <br> is valid html, and this too:

    <!DOCTYPE html>
    <html>
    <head>
       <title>I AM YOUR DOCUMENT TITLE REPLACE ME</title>
    </head>
    <body>
       <div>
    <br id="<bl>">
       </div>
    </body>
    </html>
Re:Stackoverflow, HTML by Regex, topmost answer by albertzeyer on Monday July 05, 2010 @12:40PM (#1488562)
All kind of ways you could write the br-tag are regular.
Re:Stackoverflow, HTML by Regex, topmost answer by jauco on Monday July 05, 2010 @01:49PM (#1488699)
No, because as the example shows I can put regular html in the id tag. Once you do nesting, it's not regular anymore.
Re:Stackoverflow, HTML by Regex, topmost answer by albertzeyer on Monday July 05, 2010 @03:20PM (#1488886)
You cannot nest the quotes. I.e. this is invalid:

    <br id="<br id="<br>">">
I.e. it doesn't matter what is inside the quotes.
Re:Stackoverflow, HTML by Regex, topmost answer by megaduck on Monday July 05, 2010 @12:11PM (#1488512)
The language of individual HTML tags is certainly regular, and trivially easy. However, the language of "matched HTML tags with junk between them" is NOT regular.

Anything that requires balanced matching is NOT parseable with standard Regular Expressions, and by not parseable I mean that you will literally have an infinite amount of bugs. Shoot me an email and I can show you the math.

Even with Perl's whiz-bang recursive not-really-regexes-regexes, it's strongly not recommended to tackle balanced matching problems like HTML or XML. It might be theoretically possible (I haven't actually checked), but your brain will leak from your ears and you probably won't get it right, no matter how smart you are.

Re:Stackoverflow, HTML by Regex, topmost answer by albertzeyer on Monday July 05, 2010 @12:39PM (#1488561)
But the OP asked for parsing just for a specific type of tag (which is regular). Not an area of text between open/close tags (which is not regular).
Re:Stackoverflow, HTML by Regex, topmost answer by vog on Monday July 05, 2010 @09:50AM (#1488185)
That's what I'm wondering, too.

If it was XML, one might get in trouble with "<[CDATA[" sections, but regarding HTML, I don't see a real issue here.

... especially not from the pragmatic point of view. Depending on the use case and the quality of the HTML source, a "dirty" regex hack might be a far better solution and using a DOM parser.

Re:Stackoverflow, HTML by Regex, topmost answer by jvdh on Monday July 05, 2010 @07:07AM (#1487929)
> HTML tags lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liq​uid pain

Just reading that makes me wince.

Re:Stackoverflow, HTML by Regex, topmost answer by arethuza on Monday July 05, 2010 @06:53AM (#1487914)
I'm tempted to change our bug tracker to have a bug status of "it is too late it is too late we cannot be saved".
Re:Stackoverflow, HTML by Regex, topmost answer by gvb on Monday July 05, 2010 @10:39AM (#1488275)
The terse term is "overcome by events" (OBE), applied literally.
Re:Stackoverflow, HTML by Regex, topmost answer by buro9 on Monday July 05, 2010 @08:20AM (#1488042)
The revisions for it are pretty cool too: http://stackoverflow.com/posts/1732454/revisions

Someone slightly not getting the joke edited it out on the basis of it being troll/rambling, then someone put it all back. The nice bit... the actual point is emphasised as a result.

Re:Stackoverflow, HTML by Regex, topmost answer by ars on Monday July 05, 2010 @07:21AM (#1487950)
What is necessary to make regex turing complete?
Re:Stackoverflow, HTML by Regex, topmost answer by steveklabnik on Monday July 05, 2010 @08:08AM (#1488026)
You need to be able to provide 'context.' I linked this above, but I'll link it to you, too: http://www.reddit.com/r/programming/comments/cm02a/you_cant_...
Re:Stackoverflow, HTML by Regex, topmost answer by Estragon on Monday July 05, 2010 @07:27AM (#1487957)
I had heard that perl regular expressions are already Turing complete. Never verified it, though. E.g.

http://books.slashdot.org/comments.pl?sid=143298&cid=120...

Re:Stackoverflow, HTML by Regex, topmost answer by earcar on Monday July 05, 2010 @07:51AM (#1487996)
Got to read that in a Cylon Hybrid or GLaDOS voice.
Re:Stackoverflow, HTML by Regex, topmost answer by ilkhd2 on Monday July 05, 2010 @05:19AM (#1487781)
Anybody can suggests fiction authors who write in this style - sane text morphing into gibberish and probably back to sanity?
Re:Stackoverflow, HTML by Regex, topmost answer by friism on Monday July 05, 2010 @06:07AM (#1487853)
The prose is almost certainly inspired by H. P. Lovecraft. "At the Mountains of Madness" may be a good start, if you like this sort of stuff: http://www.dustylibrary.com/horror/5-at-the-mountains-of-mad...
Re:Stackoverflow, HTML by Regex, topmost answer by steveklabnik on Monday July 05, 2010 @08:07AM (#1488023)
Yes, the entire Zalgo meme is vaguely inspired by Lovecraft.
Re:Stackoverflow, HTML by Regex, topmost answer by bigiain on Monday July 05, 2010 @08:09AM (#1488027)
Try a book called "Random Acts of Senseless Violence" by Jack Womack. The text doesn't morph into gibberish, but the lead character transforms from entitled middle class to borderline psychopath street kid, and the way the language changes as the story progresses is _wonderful!_
Re:Stackoverflow, HTML by Regex, topmost answer by ivank on Monday July 05, 2010 @06:06AM (#1487849)
Mark Z. Danielewski's House of Leaves
Re:Stackoverflow, HTML by Regex, topmost answer by djacobs on Monday July 05, 2010 @11:37AM (#1488422)
I definitely got HoL vibes reading the post.
Re:Stackoverflow, HTML by Regex, topmost answer by Russelldb on Monday July 05, 2010 @05:51AM (#1487828)
William S. Burroughs
Re:Stackoverflow, HTML by Regex, topmost answer by wlievens on Monday July 05, 2010 @09:07AM (#1488117)
It reminded me mostly of the gibberish from the Cylon hybrids in Battlestar Galatica.
Re:Stackoverflow, HTML by Regex, topmost answer by kurumo on Monday July 05, 2010 @11:13AM (#1488355)
Robert Anton Wilson

Schrödinger's Cat trilogy especially

Re:Stackoverflow, HTML by Regex, topmost answer by nuxi on Monday July 05, 2010 @12:30PM (#1488550)
Hmm, Joyce's Finnegans Wake? You did say "probably back".
Re:Stackoverflow, HTML by Regex, topmost answer by arethuza on Monday July 05, 2010 @08:29AM (#1488054)
Thomas Pynchon?