import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(\\d*?)(?:, )?([a-zéèàçù -]+?)\\n(\\d\\d ?\\d\\d\\d) ([a-z- ]+?)$";
final String string = "61, avenue de Gauthier\n"
+ "81 516 Michel-sur-Paris\n\n"
+ "6, boulevard de Nguyen\n"
+ "02 998 Techer\n\n"
+ "boulevard Lucie Bouvet\n"
+ "16 345 Morel-sur-Marques\n\n"
+ "7, impasse Francois\n"
+ "29172 Deschampsnec\n\n"
+ "30, place Lucy Guillot\n"
+ "94 786 Texier-sur-Rolland\n\n"
+ "rue de Pruvost\n"
+ "91 147 Brun\n\n"
+ "boulevard Amélie Martin\n"
+ "56243 Godard\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | 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