import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<\\/thead>((\\s.*?)+)<\\/table>";
final String string = "<div class=\"row\">\n"
+ " <div class=\"col-sm-12 ui-resizable\" data-type=\"container-content\"><div data-type=\"component-text\">\n"
+ " <h4>$company_name</h4>\n"
+ " </div>\n"
+ " <div data-type=\"component-text\">\n"
+ " <table class=\"table table-bordered table-md\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th>Item Name</th>\n"
+ " <th>Quantity</th>\n"
+ " <th>Rate</th>\n"
+ " <th>Gross</th>\n"
+ " \n"
+ " \n"
+ " \n"
+ " <th>Discount</th>\n"
+ " <th>GST</th>\n"
+ " </tr>\n"
+ " </thead>\n"
+ " <tbody id=\"table-body\">\n"
+ " <tr>\n"
+ " <td class=\"tab-data\">$table_item_name</td>\n"
+ " <td class=\"tab-data\">$table_quantity</td>\n"
+ " <td class=\"tab-data\">$table_rate</td>\n"
+ " <td class=\"tab-data\">$table_gross</td>\n"
+ " \n"
+ " \n"
+ " \n"
+ " <td class=\"tab-data\">$row_108</td>\n"
+ " <td class=\"tab-data\">$row_109</td>\n"
+ " </tr>\n"
+ " </tbody>\n"
+ " </table>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>";
final Pattern pattern = Pattern.compile(regex, 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