import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\d{1,11}";
final String string = "12976000673:Marcel da Costa\n"
+ "1239583003:Sergio Schiavinatto Silva\n"
+ "12981149464:Camila Rodrigues\n"
+ "12991633389:Silvio Carlos\n"
+ "1239587535:Jose Antonio\n"
+ "12981621899:Roberto Andrea\n"
+ "12974087508:Isaias Monteiro\n"
+ "12974052936:Mariza Innocente\n"
+ "1239533666:Rubens Sebastiao\n"
+ "12981258115:Nilberto de Almeida\n"
+ "12997796868:Rubens Amancio\n"
+ "1139582099:Jorge Abrao\n"
+ "1139583003:Luiz Carlos\n"
+ "1239214446:Abrao Gassul\n"
+ "12991018779:Joao Pedro\n"
+ "1239582099:Bastiao Silva\n"
+ "1210408957:Pedro de Santos\n"
+ "1239587511:Carlos Maya\n"
+ "1239517008\n"
+ "12981331001\n"
+ "1239581490\n"
+ "12981230081\n"
+ "12991633389\n"
+ "12981356840\n"
+ "12981356529\n"
+ "12981356844\n"
+ "12981258115\n"
+ "12997796868\n"
+ "12981455770\n"
+ "12997171890\n"
+ "12997182987\n"
+ "1139539755\n"
+ "1239529338\n"
+ "1239539755\n"
+ "12976000673\n"
+ "1260032061\n"
+ "1236314341";
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