这似乎是一个简单的问题,但我在正则表达式方面遇到了麻烦。我需要一个能够检测//不在引号内的正则表达式。
E.g:
//comment
String ex = "//I do not need to detect this";
答案 0 :(得分:0)
正则表达式/\/\/((?:(?!\/\/)[^\n])+)$/gm
将捕获所有评论。
//comments here
String ex1 = "//I do not need to detect this"; //but I need this
String ex2 = "//I do not need to detect this";
String ex3 = "//I do not need to detect this";// this also
将分别返回comments here
,but I need this
和this also
。
希望这是你想要的!