import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?s)(\\d{10}\\sDELIVERED)((.(?!\\d{10}\\sDELIVERED))*)(?<=\\$\\d\\d\\d.\\d\\d)";
final String string = "7605625112 DELIVERED N 1 GORDON CONTRACTORS I SIPLAST INC Freight Priority 2000037933 $216.67 1,131 ROOFING MATERIALS\n"
+ "04/23/2021 02:57 PM K WRISHT N 4 CAPITOL HEIGHTS, MD ARKADELPHIA, AR Prepaid 2000037933 -$124.23 170160-00\n"
+ "04/27/2021 12:41 PM 2 40 20743-3706 71923 $.00 055 $.00\n"
+ "2 WBA HOT $62.00 0\n"
+ "$12.92 $92.44\n"
+ "$167.36\n"
+ "7605625123 DELIVERED N 1 SECHRIST HALL CO SIPLAST INC Freight Priority 2000037919 $476.75 871 PAIL,UN1263,PAINT,3,\n"
+ "04/23/2021 02:57 PM S CHAVEZ N 39 HARLINGEN, TX ARKADELPHIA, AR Prepaid 2000037919 -$378.54\n"
+ "04/27/2021 01:09 PM 2 479 78550 71923 $.00 085 $95.35\n"
+ "2 HRL HOT $62.00 21\n"
+ "$13.55 $98.21\n"
+ "$173.76\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