import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "#opening tag\n"
+ "\\{(RAW|ACCESS|DWNLINK|MODL|\\w+)\n"
+ " #optional attributes\n"
+ " (?>\n"
+ " \\{ ([^\\}]*) \\}\n"
+ " )?\n\n"
+ "\\}\n\n\n"
+ "#optional text and closing tag\n"
+ "(?:\n"
+ " ( #text:= any char except \"\\{\", or a \"\\{\" not followed by /commandname\n"
+ " [^\\{]*+\n"
+ " (?>\\{(?!/?\\1[\\{\\}])[^\\{]*)*?\n"
+ " )\n\n"
+ " #closing tag\n"
+ " \\{/\\1\\}\n"
+ ")?";
final String string = "<div class=\"blog-list-item blog\"><header class=\"entry-title\">\n"
+ " <h1>Welcome to our website</h1>\n"
+ " </header><article id=\"entry-72\" class=\"entry post-72 page et-bg-layout-dark et-white-bg\"><div class=\"jumbotron row\">\n"
+ "<div class=\"col-md-8\">\n"
+ "<ul>\n"
+ "<li>You have a pending job on your neck?…</li>\n"
+ "<li>Do your company need a website makeover ?…</li>\n"
+ "<li>Or a competitive web application ? ?…</li>\n"
+ "<li>Do you need a customized plugin, or a tweak ?…</li>\n"
+ "<li>Maybe you want a personal website ?…</li>\n"
+ "<li>Or a graphic for your new project ?…</li>\n"
+ "</ul>\n"
+ "<div class=\"bg-primary well\">\n"
+ "<h4 class=\"text-center text-white shadow\">Track your project as we work it to perfection...</h4>\n"
+ "</div>\n"
+ "</div>\n"
+ "<div class=\"pull-right col-md-4\">\n"
+ "<h4 class=\"bg-primary text-white well\">Other services we offer</h4>\n"
+ "{ACCESS{type=500}}\n"
+ "<ul>\n"
+ "<li>SEO work for an existing website or new</li>\n"
+ "<li>Bulk SMS</li>\n"
+ "<li>E-currency exchange</li>\n"
+ "<li>Facebook AD</li>\n"
+ "<li>Google AD</li>\n"
+ "</ul>\n"
+ "{/ACCESS}</div>\n"
+ "{RAW{say=email,access=500}} {RAW} <a class=\"btn button large tall green\" href=\"client-area\">Place new Job now as we deliver at the quickest <em>reasonable time</em></a>{/RAW}</div></article></div>";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.COMMENTS);
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