import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "--([a-z\\d]+)-A--[\\s\\S]+?--\\1-Z--";
final String string = "--f15a0000-A--\n"
+ "[30/Aug/2018:14:06:33 +0200] W4fdyYHC0Xb8YDuIqk5YQgAAAD0 127.0.0.1 55454 127.0.0.1 80\n"
+ "--f15a0000-B--\n"
+ "GET /FormValidation/page1.php HTTP/1.1\n"
+ "Host: localhost\n"
+ "Connection: keep-alive\n"
+ "Upgrade-Insecure-Requests: 1\n"
+ "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\n"
+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\n"
+ "Referer: http://localhost/FormValidation/\n"
+ "Accept-Encoding: gzip, deflate, br\n"
+ "Accept-Language: en-US,en;q=0.9\n"
+ "tanuser: 00198343\n\n"
+ "--f15a0000-F--\n"
+ "HTTP/1.1 200 OK\n"
+ "X-Powered-By: PHP/5.6.35\n"
+ "Content-Length: 851\n"
+ "Keep-Alive: timeout=5, max=99\n"
+ "Connection: Keep-Alive\n"
+ "Content-Type: text/html; charset=UTF-8\n\n"
+ "--f15a0000-Z--\n\n"
+ "--bb410000-A--\n"
+ "[30/Aug/2018:14:06:37 +0200] W4fdzYHC0Xb8YDuIqk5YQwAAAD0 127.0.0.1 55454 127.0.0.1 80\n"
+ "--bb410000-B--\n"
+ "POST /FormValidation/validation.php HTTP/1.1\n"
+ "Host: localhost\n"
+ "Connection: keep-alive\n"
+ "Content-Length: 33\n"
+ "Accept: */*\n"
+ "Origin: http://localhost\n"
+ "X-Requested-With: XMLHttpRequest\n"
+ "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\n"
+ "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\n"
+ "Referer: http://localhost/FormValidation/page1.php\n"
+ "Accept-Encoding: gzip, deflate, br\n"
+ "Accept-Language: en-US,en;q=0.9\n"
+ "tanuser: 00198343\n\n"
+ "--bb410000-C--\n"
+ "name1=test&email1=ssn%40gmail.com\n"
+ "--bb410000-F--\n"
+ "HTTP/1.1 200 OK\n"
+ "X-Powered-By: PHP/5.6.35\n"
+ "Content-Length: 17\n"
+ "Keep-Alive: timeout=5, max=98\n"
+ "Connection: Keep-Alive\n"
+ "Content-Type: text/html; charset=UTF-8\n\n"
+ "--bb410000-Z--";
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