import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\s*<script.*>)((\\s|.)*)(<\\/script\\s*?>)";
final String string = "<script type=\"text/template\" data-category=\"text\" data-img-src=\"section-01.jpg\" data-section-name=\"1\">\n"
+ "<div class=\"zpsection\" data-element-type=\"section\">\n"
+ " <div class=\"zpcontainer\">\n"
+ " <div class=\"zprow\" data-element-type=\"row\" data-column-ratio=\"12,12\">\n"
+ " <div class=\"zpcol-md-12 zpcol-sm-12\" data-element-type=\"column\">\n"
+ " <div class=\"zpelement zpelem-heading\" data-element-type=\"heading\">\n"
+ " <h2 class=\"zpheading zpheading-align-center\" data-editor=\"true\">The face of the moon was in shadow</h2>\n"
+ " </div>\n"
+ " <div class=\"zpelement zpelem-text\" data-element-type=\"text\">\n"
+ " <div class=\"zptext zptext-align-center\" data-editor=\"true\">\n"
+ " <p>Almost before we knew it, we had left the ground. All their equipment and instruments are alive.Mist enveloped the ship three hours out from port. The spectacle before us was indeed sublime.A red flair silhouetted the jagged edge of a wing.</p>\n"
+ " </div>\n"
+ " </div>\n"
+ " <div class=\"zpelement zpelem-button\" data-element-type=\"button\">\n"
+ " <div class=\"zpbutton-container zpbutton-align-center\"> <a href=\"javascript:;\" class=\"zpbutton-wrapper zpbutton zpbutton-type-primary zpbutton-size-md\"> <span class=\"zpbutton-content\">Get Started Now</span> </a> </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ "</div>\n"
+ "</script>\n";
final Pattern pattern = Pattern.compile(regex);
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