3 ms·
I think you are right about there being an error. I didn't try running the code but it looks like it would match everything inside the html comment braces, but
by rplevy 18y ago
I think you are right about there being an error. I didn't try running the code but it looks like it would match everything inside the html comment braces, but incorrectly stop at any occurrence of '-' instead of stopping matching only at '-->' which I assume is what is actually desired there.
So it should be /(.X?<!--)(..X?)-->(.X$)/ instead.
(Note I am using X as asterix because HN at the time of this writing converts asterisks to italics tags.)
But other than that the Perl is perfectly fine. And it is easily readable if you know Perl.
- rplevy 18y agoI think this version would be clearer though: print $_ . "\n" foreach ((<>) =~ /<!--(..*?)-->/g);