Suppose I have this text:
cat file
/* comment */ not a comment /* another comment */
/* delete this *
/* multiline *
/* comment */
/*************
/* and this *
/************/
The End
I can use the perl
with a conditional ? :
to delete only the multiline comment:
perl -0777 -pE 's/(\/\*(?:\*(?!\/)|[^*])*\*\/)/($1=~qr"\R") ? "" : $1/eg;' file
Prints:
/* comment */ not a comment /* another comment */
The End
Without the conditional:
perl -0777 -pE 's/(\/\*(?:\*(?!\/)|[^*])*\*\/)//g;' file
not a comment
The End
Is there a way to delete only multiline C style comments with a regex only? ie, not use the perl conditional code in the replacement?