Regex matches ne fonctionne pas
Bonjour, voila le problème j'ai un fichier texte avec plusieurs lignes dedans et j'aimerais afficher uniquement les lignes que je veux et vu que les lignes sont différentes d'un fichier texte à un autre je voudrais utiliser une regex comme ça j'aurais pas à faire plusieurs conditions, le souci c'est que je n'arrive pas à faire fonctionner le regex, effectivement j'ai fais
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
String regex = "[a-zA-Z]";
while ((ligne = br.readLine()) != null) {
// Suite de condition permettant d'extraire des lignes grace a leurs debut
if(ligne.startsWith("Photographer : ")) {
System.out.println(ligne);
photographer = ligne.substring(15);
}else if (ligne.startsWith("Photo URL")) {
System.out.println("Photo URL : " + ligne.substring(52,61));
photo_url = ligne.substring(52,61);
}else if(ligne.startsWith("Taken Date")) {
System.out.println(ligne);
Taken_Date = ligne.substring(12);
}else if(ligne.matches(regex)) {
System.out.println("Titre : " + ligne);
titre = ligne.substring(0);
}else if (ligne.startsWith("Ap")) {
System.out.println("Description : " + ligne);
description = ligne.substring(0);
}else if(ligne.startsWith("N",1)) {
System.out.println("Tags : " + ligne.substring(0));
tags = ligne.substring(0);
}
}
br.close();
}catch (Exception e) {
System.out.println(e.toString());
} |
Mais la ligne --> ligne.matches(""^[a-zA-Z-]") ne fonctionne absolument pas et je ne sais pas pourquoi
Si des gens pourrait m'eclairer ca serais super sympa
Une bonne journée à vous