import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^.*(Set Cookie:|Set-Cookie:|HTTP|200 OK|Cookie:|document\\.?cookie).*$";
final String string = "svc_test\n"
+ "adm_test\n"
+ "eac_test\n"
+ "passaccount\n"
+ "pass_fail\n"
+ "pa_ssfail\n"
+ "Set Cookie:\n"
+ "Set-Cookie: <cookie-name>=<cookie-value>\n"
+ "HTTP/2.0 200 OK\n"
+ "document.cookie\n"
+ "//ES5\n\n"
+ "if (document.cookie.split(';').some(function(item) {\n"
+ " return item.trim().indexOf('reader=') == 0\n"
+ "})) {\n"
+ " console.log('The cookie \"reader\" exists (ES5)')\n"
+ "}\n\n"
+ "//ES2016\n\n"
+ "if (document.cookie.split(';').some((item) => item.trim().startsWith('reader='))) {\n"
+ " console.log('The cookie \"reader\" exists (ES6)')\n"
+ "}\n";
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