How to find this pattern using regex?
C style block comments
/* xxxxxxxxxxxx */
Join Stack Overflow to learn, share knowledge, and build your career.
Try using
\/\*(\*(?!\/)|[^*])*\*\/
to capture single line and multi-line block comments. It searches for /*
followed by any number of either:
*
that is not followed by a /
*
and then the closing */
again.
[^*/]
has them covered. All the |\s
does is open you up to catastrophic backtracking. Also, you need to get that slash out of there, or your regex will fail to match comments with slashes inside them.
– Alan Moore
Apr 23 '13 at 11:13
r"/[*]([^*]|([*][^/]))*[*]/"
as it worked in python !
– shuva
Jan 13 '18 at 21:13
/* ... **/
since the second to last star would match [*][^/]
, but this also eats the final star. As a quick fix I used r"/[*]([^*]|([*][^/]))*[*]+/"
(note the extra plus at the end, allowing additional trailing stars.)
– Charles Ofria
Apr 14 '19 at 16:37
/*
is on the same line and after a//
, meaning it does not start a comment? – Patashu Apr 23 '13 at 3:04