Ranzit Ranzit -3 years ago 63
Java Question

regular expression matching fully qualified java variable

Is there any regular expression to match the fully qualified java variables?

For ex: to get the variable name from the following example line.

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

Answer Source
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);
}

Will match any assignment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download