import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<center>(.|\\n)*<\\/center>";
final String string = "</head>\n\n"
+ "<body style=\"background-color:#9b9b9b;\">\n"
+ "**<center>\n"
+ "<table width=\"580\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class =\"responsive-table\" style=\"background-color:#3e5b3e;border:solid thin #3e5b3e;\" >\n"
+ " <tbody>\n"
+ " <tr>\n"
+ " <td background=\"http://app.randomsite.com/js/ckfinder/userfiles//images/banner.jpg\" style=\"padding-top:20px;padding-right:20px;padding-left:20px;\" class=\"hideForMobile\"><h1 style=\"font-family:Arial, Helvetica, sans-serif;font-size:20px;font-weight:bold;text-align:right;color:#eee;vertical-align:bottom;text-decoration:none;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;\" >some message</h1></td>\n"
+ " </tr>\n"
+ " <tr>\n"
+ "</center>**\n"
+ " <!---Start of Banner Image--->\n"
+ " <td><a href=\"{{Custom1}}\" style=\"color:inherit;text-decoration:none;\" ><img src=\"http://app.clientcommand.com/js/ckfinder/userfiles//images/top-dollar-ford-banner.jpg\" alt=\"\" class=\"table.responsiveImage\" style=\"display:block;width:100%;border-style:none;\" /></a></td>\n"
+ " <!---End of Banner Image--->\n"
+ " </tr>\n"
+ " <tr>";
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