匹配C样式多行注释的Regex
                    
                    
                3 回答
                            缥缈止盈
                            
                                
                            
                        
                        
                                                
                    TA贡献2041条经验 获得超4个赞
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解释说:
匹配字符“/”字面上 
匹配字符“*”字面意思 
“.”匹配任何单个字符 
“*?”在零和无限倍之间,尽可能少,根据需要扩展(懒惰) 
匹配字符“*”字面意思 
匹配字符“/”字面上 
//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);参考资料:
- 3 回答
 - 0 关注
 - 484 浏览
 
添加回答
举报
0/150
	提交
		取消
	