import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "Date:\\n(.*)\\n\\nNumber";
final String string = "Voice Mail Message: Double click on the attachment to play the voice mail file.\n\n"
+ "Date:\n"
+ "12/01/2014 01:28:36 PM\n\n"
+ "Number:\n"
+ "800-123-4567, JOHN SMITH\n\n"
+ "CallerID:\n"
+ "123-456-7890, JANE DOE\n\n"
+ "Destination:\n"
+ "Voice Mail\n\n"
+ "File Duration:\n"
+ "00:00:37\n\n"
+ "======================\n\n"
+ "Name : Jane Doe\n\n"
+ "Address : 123 Fake Street , Miami , Florida \n\n"
+ "Phone : 123-456-7890\n\n"
+ "Ye, my name is Jane Doe. I own the property at 123 Fake Street , Miami , Florida. You sent me a couple of postcards. Let me know if you're interested in making an offer. it's a single family home.3 bedrooms, 2 baths. Has a single efficiency in the back, that's an additional rental income.\n\n"
+ "Again, Jane Doe and that's 123 Fake Street and my phone number is 123-456-7890. Thanks !\n";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
if (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