代码有单行注释,有多行注释,需要提取在单引号或双引号里的中文(含当前中文所在引号的其它字符),一行里可能有多个引号组
代码范例入下:
class test
{
public static void main(String[] args)
{
//这是注释1!!!!
System.out.println("Hello,世界!");
System.out.println("你好,世界!");
System.out.println("你好,World");
System.out.println("Hello, world!").println("SSS, SSS!");
System.out.println("Hello, world!").println("同学, good!");
//这是注释2!!!
/*****这是多行注释1
* 这是多行注释2
* System.out.println("这是注释里的中文,不提取!!!");
* 这是多行注释3
**********/
}
}
需要提取的内容如下:
Hello,世界!
你好,世界!
你好,World
同学, good!
String regex = "^(?!.*?(\\*|//|/\\*|\\*/).*).*?[\"']([^\"']*?[\\u4e00-\\u9fa5]+[^\"']*?)[\"'\''].*?$";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher matcher = pattern.matcher(sql);
while (matcher.find()){
System.out.println(matcher.group(2));
}