0

是否有任何正则表达式来匹配完全限定的 java 变量?

例如:从以下示例行中获取变量名称。

public static final ByteOrder BIG_ENDIAN = ByteOrder.BIG_ENDIAN;
  ByteOrder order = null;
4

1 回答 1

1
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);
}

将匹配任何作业。

于 2013-01-07T05:46:47.477 回答