import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<src_ip>\\d{0,2}\\.\\d{0,2}\\.\\d{0,2}\\.\\d{0,2})\\s(?<signture>%(?<product>ASA))-(?<version>(?<release>\\d+)-(?<build>\\d+)):";
final String string = "May 9 14:30:00 10.25.8.3 %ASA-6-302013: Built outbound TCP connection 1032748840 for MGM-CML-NON-LB-SRV-Log:10.25.3.21/9997 (10.25.3.21/9997) to MIT-IBMgmt-NW:10.70.21.165/4379 (10.70.21.165/4379)";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (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));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html