import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<date>\\d[\\d:.]+)\\W+(?<InPorts>\\d+):\\s*(?<OutPort>\\d+)\\W+G-MST:\\s*(?<GMST>\\w+)\\W+guid=(?<Guid>[^\"]+)\"\\W+(?<SourceIP>\\d{1,3}(?:\\.\\d{1,3}){3})\\W+(?<targetIP>\\d{1,3}(?:\\.\\d{1,3}){3})\\W+(?<SourceSpeed>\\d+)\\W+(?<TargetSpeed>\\d+)\\D+(?<AudioType>\\d+)\\D+(?<rsn>\\d+)\\W+(?<utc>\\d[\\d.:]*)\\D+(?<pl>\\d+)\\D+(?<s>\\d+)\\D+(?<r>\\d+)\\D+(?<l>\\d+)\\D+(?<j>\\d+)\\D+(?<u>\\d+)\\D+(?<o>\\d+)\\D+(?<flags>0x\\d+).*?:(?<sip>[^\"]*)\"\\D+(?<vpn>\\d+)";
final String string = "08:07:46.914 ( 1708: 8624) G-MST: 400000EF \" guid=00040000-73b2-5c7f-2295-00104941e7b0\" (\"10.10.60.3\",\"10.10.29.251\"),(10292, 59046),2(ULaw),rsn:1,12:05:15.623 (UTC),pl:20,(s:7525, r:7557, l:0),(j:0,u:27037,o:0) flgs:0x00000000 \"sip:TGrp_5,p111@10.10.60.3:5441\",vpn:0";
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));
}
}
}
}
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