缥缈止盈
尝试使用此regex(仅单行注释):String src ="How are things today /* this is comment */ and is your code /* this is another comment */ working?";String result=src.replaceAll("/\\*.*?\\*/","");//single line commentsSystem.out.println(result);REGEX解释说:匹配字符“/”字面上匹配字符“*”字面意思“.”匹配任何单个字符“*?”在零和无限倍之间,尽可能少,根据需要扩展(懒惰)匹配字符“*”字面意思匹配字符“/”字面上或者,下面是对单行和多行注释的regex,方法是添加(?)://note the added \n which wont work with previous regexString src ="How are things today /* this\n is comment */ and is your code /* this is another comment */ working?";String result=src.replaceAll("(?s)/\\*.*?\\*/","");System.out.println(result);参考资料:https:/www.正则-表达式.info/examplesProgrammer.html