Differenze tra le versioni di "Programmazione:Java/Eclipse RCP/Documentazione Framework/Regular Expression Utility"
Da WikiSitech.
Vai alla navigazioneVai alla ricercaRiga 5: | Riga 5: | ||
</code> | </code> | ||
− | + | '''boolean match(String filter, String text)''' | |
Effettua il match tra il filtro e il testo passato convertendo prima il filtro in regular expression: | Effettua il match tra il filtro e il testo passato convertendo prima il filtro in regular expression: | ||
Versione delle 12:55, 26 mar 2008
public class FWKRegExpUtil {
public static boolean match(String filter, String text);
}
boolean match(String filter, String text) Effettua il match tra il filtro e il testo passato convertendo prima il filtro in regular expression:
- Converte "*" in ".*".
- Converte i caratteri riservati come il "+" e "$" in "[+]" e "[$]".
- Gestisce gli spazi bianchi come "*" a meno che non contenuto in ' '.
- Aggiunge in cima al filtro "^" e alla fine "$" in modo da non effettuare il match sul contenuto ma sulla frase esatta.
Esempio:
String test = "ab c d efg";
FWKRegExpUtil.match("a", test); // FALSE
FWKRegExpUtil.match("a*", test); // TRUE
FWKRegExpUtil.match("'a b c'*", test); // FALSE
FWKRegExpUtil.match("'ab c'*", test); // TRUE
FWKRegExpUtil.match("a b c", test); // TRUE