是否有任何正则表达式来匹配完全限定的 java 变量?
例如:从以下示例行中获取变量名称。
public static final ByteOrder BIG_ENDIAN = ByteOrder.BIG_ENDIAN;
ByteOrder order = null;
String z = "public static final ByteOrder BIG_ENDIAN = ByteOrder.BIG_ENDIAN;\nByteOrder order = null;";
Pattern pattern = Pattern.compile("[^ =]+[ ]*=[^=]");
Matcher matcher = pattern.matcher(z);
while (matcher.find()) {
String match = matcher.group();
match = match.substring(0, match.length()-2).trim();
System.out.println(match);
}
将匹配任何作业。