import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<Row.+?>((?:\\n.*?)*)<\\/Row>";
final String string = "<Row ss:AutoFitHeight=\"0\">\n"
+ "<Cell ss:StyleID=\"s69\"><Data ss:Type=\"String\">LcolDefs:</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s69\"><Data ss:Type=\"String\">Lkeywords:</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s69\"><Data ss:Type=\"String\">TestProcedure</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "</Row>\n"
+ "<Row ss:AutoFitHeight=\"0\">\n"
+ "<Cell ss:StyleID=\"s71\"><Data ss:Type=\"String\">LsetupTest:NMTA-1772</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s72\"><Data ss:Type=\"String\">DROP4</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s71\"><Data ss:Type=\"String\">TEX::stepCatch log::log notice \"start NMTA-1772\"</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s73\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "</Row>\n"
+ "<Row ss:AutoFitHeight=\"0\" ss:StyleID=\"s74\">\n"
+ "<Cell ss:StyleID=\"s69\"><Data ss:Type=\"String\">LcolDefs:</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s69\"><Data ss:Type=\"String\">Lkeywords:</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s69\"><Data ss:Type=\"String\">TestProcedure</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s75\"><Data ss:Type=\"String\">Ljoin:Host</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s75\"><Data ss:Type=\"String\">Ljoin:Port</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:typeGroup</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:ipAddress</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:connectionType</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:port</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:username</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:password</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s76\"><Data ss:Type=\"String\">Lparam:id</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s77\"><Data ss:Type=\"String\">Lparam:-code</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s77\"><Data ss:Type=\"String\">Lparam:-pollGetNc</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s77\"><Data ss:Type=\"String\">Lparam:-checkNe</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s77\"><Data ss:Type=\"String\">Lparam:-checkDup</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s77\"><Data ss:Type=\"String\">Lparam:-initializeVar</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s77\"><Data ss:Type=\"String\">Lparam:-convertToJson</Data></Cell>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "<Cell ss:StyleID=\"s70\"/>\n"
+ "</Row>\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