通用注释有两种:

1、//

2、/*......*/

 

通常情况下,行级注释可以这样匹配

\/\/[^\n]*

块级别这样

\/\*([^\*^\/]*|[\*^\/*]*|[^\**\/]*)*\*\/

或者还可以这样

\/\*(\s|.)*?\*\/

 

不过在特殊情况中,行级别会跟协议前缀冲突,所以还需要特殊处理

(?<!http:)\/\/.*

甚至于不限定于http协议

(?<!:)\/\/.*

 

最终处理注释为:

/**
     * 处理注释 groovy代码
     * @param text
     * @return
*/
    def removeComment(text) {
return text.replaceAll("(?<!:)\\/\\/.*|\\/\\*(\\s|.)*?\\*\\/", "")
    }