Reference \[(?<REFERENCE>[a-zA-Z0-9]+)\] was
Reference # String
\[ # Eckige Klammer
(?<REFERENCE> # Beginn einer benannten Gruppe
[a-zA-Z0-9]+ # Inhalt von den eckigen Klammern.
) # Ende der benannten Gruppe
\] # Eckige Klammer
was # String
"Reference \\[..."
.import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "Reference \\[(?<REFERENCE>[a-zA-Z0-9]+)\\] was";
final String string = "Reference [y9ISPFp32I0] was closed: [SOME_STATUS].";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}