import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^([cC]\\/|[cC]alle|[aA]v\\/|[aA]venida|[pP]laza\\/|[pP]laza)\\s([A-z ]{0,})\\,\\s\\d+$";
final String string = "calle prueba, 2\n"
+ "calle de la prueba, 5\n"
+ "Avenida de la prueba, 5\n"
+ "Plaza de la prueba, 5\n"
+ "Calle Higuereta, 4, 7º B\n"
+ "Calle Escritor Conde Zamora s/n\n"
+ "Avenida Ciudad de Aranjuez 18\n"
+ "Avenida Pintor Sorolla 125 4ºG\n"
+ "Polígono Industrial Aranguren 6\n"
+ "Calle Gremi Passamaners 24 2º\n"
+ "Avenida Manuel Rodriguez Ayuso, 170\n"
+ "Calle Illa de Buda 55\n"
+ "C/ Walia, 21 \n"
+ "C/Alfonso Pesquera, 6";
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