3 ms·
Here is a regular expression for C++-style comments (/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*) (source: http://ostermiller.org/findcomment.html htt
by cabalamat 17y ago
Here is a regular expression for C++-style comments
(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)
(source: http://ostermiller.org/findcomment.html http://ostermiller.org/findcomment.html )
I recently wrote a lexicasl analyser for a language that uses C++-style comments. My first attempt used regular expressions, but I later scrapped them for something I could understand. Here is the relevant bit:
# //... comments
if ss.isNextSkip("//"):
ss.skipPast("\n")
return
# /*...*/ comments
if ss.isNextSkip("/*"):
ss.skipPast("*/")
return
I will leave it to the reader to decide which is clearer.