import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^.+,.+\\n.+\\n.+\\n\\s";
final String string = "...\n"
+ "830 ORLANDO, 382.000CS $ \n"
+ "FL 16.2400 \n"
+ "840 TAMPA, FL 382.000CS $ \n"
+ "16.2400 \n"
+ "Subtotal 41,310.000CS \n"
+ "Contract Total 115,560.000CS $ 1,569,663.00 \n\n"
+ " \n"
+ "Contractor Total 115,560.000 C S $ 1,569,663.00 \n"
+ "ABC, INC. \n"
+ "PO Box 11 \n"
+ "NEW YORK, NY 11111-1111 \n"
+ " \n"
+ " \n"
+ "SOME RANDOM COMMODITY \n"
+ "90 New York, NY 39,900.000LB $ \n"
+ "0.4925 \n"
+ "110 CLEVELAND, OH 39,900.000LB $ \n"
+ "0.4925 \n"
+ "...";
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