Programmazione:Java/Eclipse RCP/Documentazione Framework/Regular Expression Utility
Da WikiSitech.
Versione del 26 mar 2008 alle 12:41 di Rimondini (discussione | contributi) (Nuova pagina: <code java> public class FWKRegExpUtil { public static boolean match(String filter, String text); } </code> ===boolean match(String filter, String text)=== Effettua il match tra il...)
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