Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Regex html
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jörg W Mittag, post: 4559962"] Whenever someone asks me how to parse HTML with regular expressions, I usually tell them: don't. HTML is an extremely complex language; if you want to parse HTML, use an HTML parser. For example, the following snippet is a perfectly well-formed and valid HTML document, but none of the regexps posted in this thread so far are able to correctly parse it: <HTML/ <HEAD/ <TITLE/>/ <P/> Oh, and, no, there is nothing missing there (well, except for the DOCTYPE declaration, I left that out for brevity -- this snippet is valid HTML 2.0, HTML 3.2 and HTML 4.01), that is actually a complete, well-formed and valid HTML document. The content of the above document's body element, flattened to a string, should be something like this: '<P>></P>'. Using an actual HTML parser like Hpricot might be a much better choice. Actually, I just checked and Hpricot doesn't seem to work either and neither does RubyfulSoup. Strange. What other Ruby HTML parsers are there that I could try? jwm [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Regex html
Top