import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=Code:).*Distribution\\s([\\d.,]+)(?=\\n)";
final String string = "Code: 210 - Test 1 - Distribution\n"
+ "267745 Vis - Branch Deposit 3/10/2021 2,000.00\n"
+ "468040 v- Branch Deposit 2/10/2021 1,700.00\n"
+ "586075 Visa 3/3/2021 555.48\n"
+ "502490 Vis 3/4/2021 1,835.51\n"
+ "403195 Vis 3/4/2021 2,033.56\n"
+ "500230 Vis 3/4/2021 651.29\n\n"
+ "Code: 210 - Test - Distribution 8,775.84\n"
+ "Code: 230 - Greenville - Distribution\n"
+ "853955 Clearing 2/1/2021 77.50";
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