2 ms·
>Regex doesn’t work fine even on that. Most of the time it works just fine for my purposes. And it's not like I don't know alternatives. And I've written a to
by coldtea 6y ago
>Regex doesn’t work fine even on that.
Most of the time it works just fine for my purposes.
And it's not like I don't know alternatives. And I've written a toy compiler in the past (C with classes subset), done heavy XSLT work, know how to write a parser (manually, with flex/yacc, with PEG), have parsed XML with SAX, DOM, XOM, have used xpath expressions, css and jquery selectors, and used libs like BeautifulSoup.
Most of the time a quick regex will do just fine for that purpose.
See, I don't intend to send the href's to the ISS or to some medical equipment that will blow up if, god forbid, I accidentally found an A tag in a comment or inside a script or attribute.
And I'll probably run another regex or simple editor or awk filter to get rid of some false positives and I'll be fine.
>If you want to parse HTML, you need a parser.
That's a tautology, so it's always true.
If on the other hand you just need to extract some information from an HTML file, and you can just open the bloddy file and see its structure and it is perfectly servicable with a regex, you might not need a parser at all. Simple as that.
- jameshart 6y agoIf you're in a situation where you know enough about both HTML and regex to know that you can definitely solve your HTML parsing problem safely using a regex... What possible question could you have for an online forum?