形如:
import java.util.regex.Pattern; //java头
com.sinoair.freight.operation.util.UserSessionInfo, // jsp头
java.util.regex.Pattern p = null; // 头中没有,程序中直接引用
...等等,想检查到这些package的行。我的写法为:
Pattern pImport = Pattern.compile("\\bimport\\s+\\S+;\\s*");
Matcher m = pImport.matcher(line);
if (m.matches()) {}....这样仅能解决第一行的格式,第二行呢?第三行呢?是不是可以利用package有多个“.”来确定?起码两个“.”吧。
可我不知道“.”的转义符号是多少。