import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=Amount:\\s?\\$)([0-9,]+\\.\\d{2})|(?<=Date:\\s?)(\\d{2}/\\d{2}/\\d{4})|(?<=Invoice:\\s?)(\\d+)|(?<=Billing Account Name:\\s?)([\\w\\s]+)";
final String string = "Dear Valued AdRoll Customer,\n\n"
+ "Your payment for invoice #5925702 has been processed. Please see below for additional details.\n\n"
+ "Learn more about your billing history.\n\n"
+ "-- Transaction Details --\n"
+ "Amount: $450.42\n"
+ "Date: 10/15/2024\n"
+ "Invoice: 5925702\n"
+ "Billing Account Name: RRL Exhbits\n"
+ "Profile(s):\n"
+ "Reagan Library\n"
+ "If you have any questions, please contact support@adroll.com.\n\n"
+ "Download Invoice PDF\n\n"
+ "Log in to AdRoll\n\n"
+ "---\n"
+ "If you have any questions, don’t hesitate to contact our Support team or chat with us live.";
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