2012-09-18 2 views
-2

J'ai un problème en utilisant des expressions régulières que je devrais essayer ces:Java expressions régulières minuscules haut

"<td><font size=1>LA SPEDIZIONE E' IN VIAGGIO</font></td> 
<td><font size=1>Hub Pacchi Milano</font></td>" 

Tout d'abord je devrais essayer avec majuscule puis celui avec majuscules et minuscules. Je me suis arrêté ici:

Pattern uppercase= Pattern.compile("<td><font size=1>(.*?)</font></td>"); 
Pattern lowcase = Pattern.compile("<td><font size=1>(.*?)</font></td>"); 

Voici ce que je cherche tout! Comment puis-je faire?

+2

NE PARSEZ PAS DU HTML AVEC DES EXPRESSIONS RÉGULIÈRES! Voir http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html – hsanders

Répondre

0

Bien que je recommande fortement d'utiliser un analyseur HTML décent pour extraire ces informations, pour vous débloquer avec la manière insensible à la casse d'utiliser le motif, vous pouvez utiliser les éléments suivants:

String str = 
    "<td><font size=1>LA SPEDIZIONE E' IN VIAGGIO</font></td><td><font size=1>Hub Pacchi Milano</font></td>"; 
Pattern uppercase = Pattern.compile("<td><font size=1>(.*?)</font></td>", Pattern.CASE_INSENSITIVE); 
Matcher matcher = uppercase.matcher(str); 
while (matcher.find()) 
{ 
    System.out.println(matcher.group(1)); 
} 

Sortie:

LA SPEDIZIONE E' IN VIAGGIO 
Hub Pacchi Milano 
+0

Le problème est que, en plus de ceux que je balise également html: " 29-03-2012 16:41 "par conséquent, cette méthode me rend tout! – drKucho

+0

Pourquoi cette méthode vous renverrait-elle tout si vous utilisez le groupe (1)? groupe (0) vous renverra le ..., non? – Vikdor

+0

NE PARSEZ PAS LE HTML AVEC DES EXPRESSIONS RÉGULIÈRES! Voir codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html –