4 ms·
While we're on the subject, let's not forget to avoid parsing HTML with regex: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-se
by johnnylambada 9y ago
While we're on the subject, let's not forget to avoid parsing HTML with regex: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 https://stackoverflow.com/questions/1732348/regex-match-open...
- ams6110 9y agoGenerally good advice, but can be OK in specific situations where you have a known HTML structure and are just scraping some values out of it. This is not so much parsing HTML as it is matching the patterns of the values you want to extract.
- johnnylambada 9y agothe pon̷y he comes he c̶̮omes
- jdnier 9y agoA regex can be used effectively to tokenize XML-like markup, including a lot of HTML—sometimes called shallow parsing. https://stackoverflow.com/a/6638578/234823 https://stackoverflow.com/a/6638578/234823 Attribute value minimization would be one limitation, since that regex is for XML, but it's a more robust approach than writing naive "<x>.*</x>"-style regexes.
- AceJohnny2 9y ago> A regex can be used effectively to tokenize XML-like markup ...isn't that how all tokenizers for all (confusingly-named) context-free languages work?