4 ms·
> Does your regex assumes that "-->" must be prefixed by a space? Yep, because the quoted regex assumed the same thing, and I didn't see a point in editorializ
by a1369209993 5y ago
> Does your regex assumes that "-->" must be prefixed by a space?
Yep, because the quoted regex assumed the same thing, and I didn't see a point in editorializing more than necessary.
> Also the string "--" must not occur inside a comment, so the last clause is not necessary.
"Must not" seems unreliable in webpage parsing. What page does your XHTML parser produce when fed text of the form `<!-- --is this a comment? <a href=-->`, for example?
- jameshart 5y agoThe supplied regex is using extended syntax which ignores whitespace (you can tell because it also includes comments)
- goto11 5y agoHandling invalid syntax is another can of worms! It would make all parts of the tokenizer much more complex, not just comments. In the case of XHTML, a parser is supposed to reject any document which is not well formed. HTML parsers typically try to "gracefully recover" from all syntax errors, but this is a crazy complex algorithm.