Programmazione:Java/Eclipse RCP/Documentazione Framework/Regular Expression Utility
Da WikiSitech.
Versione del 14 apr 2008 alle 10:10 di Rimondini (discussione | contributi) (ha spostato Programmazione:Java/Documentazione Framework/Regular Expression Utility a Programmazione:Java/Eclipse RCP/Documentazione Framework/Regular Expression Utility)
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