Incorporating what you've added as input:
$data =~ s{ # First, we'll list things we want # to match, but not throw away ( (?:/[^\r\n\*\/]+/) # Match RegExp | # -or- [^"'/]+ # other stuff | # -or- (?:"[^"\\]*(?:\\.[^"\\]*)*" [^"'/]*)+ # double quoted string | # -or- (?:'[^'\\]*(?:\\.[^'\\]*)*' [^"'/]*)+ # single quoted constant ) | # or we'll match a comment. Since it's not in the # $1 parentheses above, the comments will disappear # when we use $1 as the replacement text. / # (all comments start with a slash) (?: \*[^*]*\*+(?:[^/*][^*]*\*+)*/ # traditional C comments | # -or- /[^\n]* # C++ //-style comments ) }{$1}gsx;
There should be a way for us to do this, because we want to handle that 99% of code that is out there... without writing a parser...var b=/\s*;\s*/gi;
I'm thinking we need to modify the regex in the "# Match RegExp" section further, to ignore *s and \/s... this may not be easy, and if I figure it out, I'll post it here.
In reply to Re: Re: Extracting C Style Comments Revised (JavaScript)
by Incognito
in thread Extracting C Style Comments Revised (JavaScript)
by Incognito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |