import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "auth-sender:\\h+(.+)\\h*\\R*";
final String string = " Received: from mail pickup service by fakeserver.m2w.com with Microsoft\n"
+ " SMTPSVC; Tue, 3 Dec 2019 14:36:35 -0800\n"
+ "auth-sender: santaana@fakeemail.com\n"
+ "Received: from 217.165.33.125 unverified ([217.165.33.125]) by\n"
+ " mmmeb08oc.m2w.com with M2W SMTP Server;\n"
+ " Tue, 03 Dec 2019 14:36:34 -0800\n"
+ "Date: Wed, 04 Dec 2019 02:32:18 +0400\n"
+ "From: \"Coordinador MLV\" <santaana@fakeemail.com>\n"
+ "To: <8736c321fd7cc61b92396b4f275614c7@fakeemail.comm>";
final Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
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