import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*@softcomputer\\.com>? *(?:\"? *<\\S+> *)?$";
final String string = "== Real scc\n"
+ "Mary Bills <marybil@softcomputer.com>\n"
+ " <ellie@softcomputer.com>\n"
+ " <thereasaw@softcomputer.com>\n"
+ "test@softcomputer.com\n"
+ "<test@softcomputer.com>\n"
+ "olexiyry@softcomputer.com <olexiyry@softcomputer.com>\n"
+ "Deseriee Harkins <deseriee@softcomputer.com>\n\n"
+ "== Forged scc\n"
+ "Dorota Mazurek <dorotam@softcomputer.com> <reservations@nesthotel.com>\n"
+ "Nikki Taft <nicolet@softcomputer.com> <Muhammad.owais@abtach.com>\n"
+ "Lynette Didia <ldidia@softcomputer.com> <Muhammad.owais@abtach.com>\n"
+ "Dorota Mazurek <dorotam@softcomputer.com> <centralbookings@kbcsa.co.za>\n"
+ "Jeffrey Marr <jeffreym@softcomputer.com> <srvadv5.blr@vw-ppsmotors.co.in> \n"
+ "Iryna Dmytriyeva @SCC <idmy@softcomputer.com> <sc@grupoinrexsa.com>\n"
+ "Vickie Nix vickieh@softcomputer.com <m.recovery@albarondebt.com>\n"
+ "Bill Young <billyo@softcomputer.com> <sara@eaurenaissance.com>\n\n"
+ "== Questionable\n"
+ "\"Kurt Veith <kurtv@softcomputer.com>\" <marlene.robles@mld.com.mx>\n"
+ "\"softcomputer.com\" <MAIL.QUOTA@servers.com>\n"
+ "\"marksm@softcomputer.com\" <mark560sl@gmail.com>\n\n"
+ "== Valid non-forged addresses\n"
+ "\"sarahze@softcomputer.com via Smartsheet\" <user@smartsheet.com>\n"
+ "\"yuvi softcomputer.com\" <hugginshospital.notification@zixmessagecenter.com>\n"
+ "<technicalsupport@softcomputer.com.au>\n"
+ "\"Secure Email From yevgeny@softcomputer.com via Message Pickup Center\" <emx-intermedia@securemail.intermedia.net>\n"
+ "\"Secure Email From yevgeny@softcomputer.com via Message Pickup Center\" <emx-intermedia@securemail.intermedia.net>\n"
+ "\"mpettis@softcomputer.com via SurveyMonkey\" <member@surveymonkeyuser.com>";
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