import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "1";
final String string = "Telephone,Date,Zip\n"
+ "1-917-887-9281,08/02/2015,61022\n"
+ "1-614-122-0700,07/12/2013,51642\n"
+ "1-401-310-3354,04/07/2015,86161\n"
+ "1-776-738-7726,01/12/2014,61294\n"
+ "1-512-994-9175,02/02/2014,89104\n"
+ "1-401-546-6134,12/01/2014,89820\n"
+ "1-168-498-8484,21/06/2015,49526\n"
+ "1-778-253-5497,14/01/2015,98123\n"
+ "1-404-432-9739,10/09/2014,74122\n"
+ "1-629-563-3288,26/10/2013,47379\n"
+ "1-399-794-0834,21/05/2015,69891\n"
+ "1-210-801-0619,18/06/2015,79134\n"
+ "1-789-756-2201,10/07/2014,34644\n"
+ "1-673-598-4221,23/06/2015,89506\n"
+ "1-898-944-9344,02/05/2014,78701\n"
+ "1-401-926-2823,16/11/2014,38679\n"
+ "1-673-176-5233,03/09/2014,83277\n"
+ "1-670-119-0983,13/12/2013,44606\n"
+ "1-929-431-8036,21/06/2015,76118\n"
+ "1-941-986-2478,02/04/2014,38809\n"
+ "1-965-311-5298,13/02/2015,67390\n"
+ "1-966-241-2160,19/10/2014,12024\n"
+ "1-171-218-2878,16/05/2014,89757\n"
+ "1-579-696-3951,07/05/2015,88783\n"
+ "1-880-379-8249,27/05/2014,84169\n"
+ "1-729-730-5787,25/11/2014,50579\n"
+ "1-401-281-4234,28/01/2014,67149\n"
+ "1-136-687-0372,01/01/2015,88760\n"
+ "1-324-552-7773,06/12/2013,96232\n"
+ "1-460-954-6974,09/10/2014,44191\n"
+ "1-401-535-7233,17/12/2013,15725\n"
+ "1-177-661-0599,11/08/2015,58068\n"
+ "1-958-872-4163,14/02/2014,65903\n"
+ "1-751-976-1258,19/09/2015,33419\n"
+ "1-970-750-5604,08/03/2015,49727\n"
+ "1-401-311-1655,21/06/2015,16233\n"
+ "1-368-460-0652,14/04/2015,46683\n"
+ "1-561-904-8040,05/11/2013,84159\n"
+ "1-434-990-8299,19/01/2014,99741\n"
+ "1-405-919-6493,19/03/2014,92955\n"
+ "1-273-356-8382,03/03/2015,94595\n"
+ "1-969-466-0391,02/06/2014,28607\n"
+ "1-365-885-5483,09/07/2015,72921\n"
+ "1-479-782-0491,08/09/2015,90440\n"
+ "1-337-274-2635,09/01/2014,90487\n"
+ "1-126-912-0604,29/06/2015,77501\n"
+ "1-528-770-1186,16/10/2014,12597\n"
+ "1-251-239-7048,10/11/2013,56237\n"
+ "1-754-230-8264,16/11/2014,35546\n"
+ "1-257-642-5660,25/10/2014,86283\n"
+ "1-633-547-7089,26/04/2015,30792\n"
+ "1-161-604-0959,28/01/2015,83378\n"
+ "1-497-635-0092,26/07/2015,95635\n"
+ "1-926-635-0188,15/04/2014,95133\n"
+ "1-288-287-3450,08/06/2014,21739\n"
+ "1-981-694-3820,16/12/2014,12878\n"
+ "1-727-533-4754,23/05/2015,66255\n"
+ "1-310-697-1783,01/03/2014,94502\n"
+ "1-401-356-8358,10/11/2013,17172\n"
+ "1-264-760-2541,27/10/2014,61896\n"
+ "1-462-318-2842,14/12/2014,86195";
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