import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(on|date)*\\s*\\,*(mon|tue|wed|thu|fri|sat)\\,*\\s*([0-9]{2,4}|([0-9]{2}:*){1,3})\\s+(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\s+([0-9]{2,4}|([0-9]{2}:*){1,3})\\s+(([0-9]{2}:*){1,3}|[0-9]{2,4})\\s*((\\+|\\-)+(([0-9]{2}:*){1,3}|[0-9]{2,4}))*\n";
final String string = "From ilug-admin@linux.ie Wed Aug 21 13:33:23 2002\n"
+ "Return-Path: <ilug-admin@linux.ie>\n"
+ "Delivered-To: yyyy@localhost.netnoteinc.com\n"
+ "Received: from localhost (localhost [127.0.0.1])\n"
+ " by phobos.labs.netnoteinc.com (Postfix) with ESMTP id E0EBC43C34\n"
+ " for <jm@localhost>; Wed, 21 Aug 2002 08:33:21 -0400 (EDT)\n"
+ "Received: from phobos [127.0.0.1]\n"
+ " by localhost with IMAP (fetchmail-5.9.0)\n"
+ " for jm@localhost (single-drop); Wed, 21 Aug 2002 13:33:21 +0100 (IST)\n"
+ "Received: from lugh.tuatha.org (root@lugh.tuatha.org [194.125.145.45]) by\n"
+ " dogma.slashnull.org (8.11.6/8.11.6) with ESMTP id g7LCYUZ24675 for\n"
+ " <jm-ilug@jmason.org>; Wed, 21 Aug 2002 13:34:30 +0100\n"
+ "Received: from lugh (root@localhost [127.0.0.1]) by lugh.tuatha.org\n"
+ " (8.9.3/8.9.3) with ESMTP id NAA29496; Wed, 21 Aug 2002 13:33:16 +0100\n"
+ "X-Authentication-Warning: lugh.tuatha.org: Host root@localhost [127.0.0.1]\n"
+ " claimed to be lugh\n"
+ "Received: from salmon.maths.tcd.ie (mmdf@salmon.maths.tcd.ie\n"
+ " [134.226.81.11]) by lugh.tuatha.org (8.9.3/8.9.3) with SMTP id NAA29463\n"
+ " for <ilug@linux.ie>; Wed, 21 Aug 2002 13:33:07 +0100\n"
+ "Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id\n"
+ " <aa96976@salmon>; 21 Aug 2002 13:33:06 +0100 (BST)\n"
+ "To: ilug@linux.ie\n"
+ "Subject: Re: [ILUG] URGENT: Cant get a skrew out... PLEASE HELP!\n"
+ "X-It'S: all good\n"
+ "X-Wigglefluff: fuddtastic\n"
+ "X-Zippy: When this load is DONE I think I'll wash it AGAIN..\n"
+ "In-Reply-To: Your message of\n"
+ " \"Wed, 21 Aug 2002 12:42:17 BST.\"\n"
+ " <BCEFLMCEIJHPCPLGADJICEDPCAAA.kialllists@redpie.com>\n"
+ "Date: Wed, 21 Aug 2002 13:33:06 +0100\n"
+ "From: Niall Brady <bradyn@maths.tcd.ie>\n"
+ "Message-Id: <200208211333.aa96976@salmon.maths.tcd.ie>\n"
+ "Sender: ilug-admin@linux.ie\n"
+ "Errors-To: ilug-admin@linux.ie\n"
+ "X-Mailman-Version: 1.1\n"
+ "Precedence: bulk\n"
+ "List-Id: Irish Linux Users' Group <ilug.linux.ie>\n"
+ "X-Beenthere: ilug@linux.ie\n\n"
+ "On Wed, 21 Aug 2002 12:42:17 BST, Kiall Mac Innes said:\n"
+ ">Hi i have a phillips head skrew thats holding a circut board together i need\n"
+ ">to take it out ASAP and nothing will work, the threads on the skrew are\n"
+ ">almost completly gone, its is a very small skrew that i have to use a\n"
+ ">percision skrewdriver set to remove the skrews any help would be\n"
+ ">appreaciated...\n\n"
+ "Get a very, *very* small set of drill bits. Start drilling right\n"
+ "through the center of the head, at a slow speed so you don't pop\n"
+ "off and through the board! Once you have a bit of an indent in,\n"
+ "increase the speed a little bit.\n\n"
+ "If you've made a deepish indent, and the head doesn't pop off, use\n"
+ "the next largest drill bit you have. Repeat until happy.\n\n"
+ "Eventually the head should just pop off, allowing you to lift the\n"
+ "board off over the shaft of the screw... then ye can take out the\n"
+ "rest fairly easily with a pliers or whatnot.\n\n"
+ "-- \n"
+ " Niall\n\n"
+ "-- \n"
+ "Irish Linux Users' Group: ilug@linux.ie\n"
+ "http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.\n"
+ "List maintainer: listmaster@linux.ie\n\n";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
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