import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:account:(.+))(?:site:(.+))(?:zone:(.+))-->|(?:site:(.+))(?:zone:(.+))(?:size:(.+))\\s+-->|(?:placement:(.+))-->";
final String string = "<!-- Account: QA 1 Test Site: Video Test Site for Mobile Team (Nitin) Zone: ROS -->\n"
+ "http://optimized-by.rubiconproject.com/a/api/vast.xml?account_id=2763&site_id=40876&zone_id=170462 \n\n"
+ "<!-- Begin Rubicon Project Tag -->\n"
+ "<!-- Site: DOM_TOLIVER_MWEB Zone: Interstitials Size: Mobile Interstitial Landscape -->\n"
+ "<!-- PLACEMENT: Homepage; Above the Fold -->\n"
+ "<script language=\"JavaScript\" type=\"text/javascript\">\n"
+ "rp_account = '8092';\n"
+ "rp_site = '55880';\n"
+ "rp_zonesize = '340088-101';\n"
+ "rp_adtype = 'js';\n"
+ "rp_smartfile = '[SMART FILE URL]';\n"
+ "</script>\n"
+ "<script type=\"text/javascript\" src=\"http://ads.rubiconproject.com/ad/8092.js\"></script>\n"
+ "<!-- End Rubicon Project Tag -->";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | 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