I've been trying to remove single-line comments from JavaScript files using the below regex:
Pattern p = Pattern.compile("(?m)(?:[\\(|\\)|;|\\}|\\{])\\s*/{2}(.*?)$");
The pattern works when I test it in something like RegexPal using the "^$ matches line break" option on some sample JavaScript source.
However, what seems to be the problem when putting it into my Java program is that the "m" flag doesn't seem to work correctly. Essentially, even though I'm specifying the flag using the "(?m)" at the beginning of the pattern (though I've also tried using Pattern.MULTILINE), it seems to be ignoring it completely making my $ match everything through the end of the entire document rather than just the EOL.
matches()orfind()? Also, what good is it doing you to match the comments when you're actually trying to remove them? i.e. are you trying to kill them to make your source smaller, or extract them to look at them or print them out?