Reputation: 105
Is there any regular expression that is able to remove all comments of the // and /**/ variety from a given C program say in perl?
Given the multi-line program, it should use the regular expression to remove the comments and return the non-commented out portion.
Thanks.
Upvotes: 3
Views: 3422
Reputation: 91488
It's a FAQ:
How do I use a regular expression to strip C-style comments from a file?
Upvotes: 6
Reputation: 26861
Try with Regexp::Common::comment
:
use Regexp::Common qw /comment/;
while (<>) {
s/($RE{comment}{C++})//;
}
Upvotes: 7