import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "Browser((?:_type)?\\s\\\"*)(?P<UA>(.+\\\"-|[^\\\"]+))";
final String string = "7 06:51:56 netscaler02 12/07/2017:12:51:56 GMT netscaler02 0-PPE-0 : AAA LOGIN_FAILED -807443279 0 : User slwagner - Client_ip 173.172.124.235 - Failure_reason \"External authentication server denied access\" - Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3\n\n"
+ "7 06:51:56 netscaler02 12/07/2017:12:51:56 GMT netscaler02 0-PPE-0 : AAA LOGIN_FAILED -807443279 0 : User slwagner - Client_ip 173.172.124.235 - Failure_reason \"External authentication server denied access\" - Browser \"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3\"--asfashfi\n";
final Pattern pattern = Pattern.compile(regex);
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