Java – regular expression finding comments in code
You may have already given up on this by now but I was intrigued by the problem. I believe this is a partial solution… Native regex: //.*|(“(?:\\[^”]|\\”|.)*?”)|(?s)/\*.*?\*/ In Java: String clean = original.replaceAll( “//.*|(\”(?:\\\\[^\”]|\\\\\”|.)*?\”)|(?s)/\\*.*?\\*/”, “$1 ” ); This appears to properly handle comments embedded in strings as well as properly escaped quotes inside strings. I … Read more