Cet article a partagé le code spécifique de l'outil d'expression régulière Java pour votre référence. Le contenu spécifique est le suivant
Importer com.google.common.base.strings; import java.util.regex.matcher; import java.util.regex.pattern; / ** * Expressions régulières couramment utilisées * créées par TakeBra sur 2016/4/7. * / classe publique regexutils {/ ** * Déterminez s'il s'agit de l'adresse IP correcte * * @param ip * @return boolean true, pass, false, a échoué * / public static boolean isip (String ip) {if (Strings.isnullorempty (ip)) return false; String regex = "^ (1 // d {2} | 2 [0-4] // d | 25 [0-5] | [1-9] // d | [1-9]) //." + "(1 // d {2} | 2 [0-4] // d | 25 [0-5] | [1-9] // d | // d) //." + "(1 // d {2} | 2 [0-4] // d | 25 [0-5] | [1-9] // d | / d) //." + "(1 // d {2} | 2 [0-4] // d | 25 [0-5] | [1-9] // d | // d) $"; return ip.matches (regex); } / ** * Déterminez s'il s'agit de l'adresse e-mail correcte * * @param e-mail * @return booléen true, passé, false, échoué * / public static boolean isemail (chaîne e-mail) {if (Strings.isnullorempty (e-mail)) return false; String regex = "//w+(@+. return email.matches (regex); } / ** * Déterminez s'il contient le chinois, qui convient uniquement aux caractères chinois, sans ponctuation * @param texte * @return booléen true, passé, false, a échoué * / public statique booléen ischinese (texte de la chaîne) {if (Strings.isnulllorempty (texte)) return false; Pattern p = motif.compile ("[/ u4e00- / u9fa5]"); Matcher m = p.matcher (texte); retour m.find (); } / ** * Déterminez si un entier positif * * @param numéro * numéro * @return boolean true, pass, false, a échoué * / public static boolean isNumber (chaîne numéro) {if (Strings.isnullorempty (nombre)) return false; String regex = "[0-9] *"; return numéro.matches (regex); } / ** * Déterminez combien de décimales (nombres positifs) * * @param décimal * numéro * @param count * décimal chiffres * @return booléen true, pass, false, échoué * / public static booléen isDecimal (string décimal, int count) {if (strings.isnulllorempty (decimal)) return false; String regex = "^ (-)? (([1-9] {1} // d *) | ([0] {1}))) (//. (// d) {" + count + "})? $"; return Decimal.matches (regex); } / ** * Déterminez s'il s'agit d'un numéro de téléphone mobile * * @param phonenumber * numéro de téléphone mobile * @return boolean true, pass, false, a échoué * / public static booléen ismobilephonenumber (String Phonenumber) {if (Strings.isnullloreMpty (phonenumber)) return false; String regex = "^ ((13 [0-9]) | (15 [0-9]) | (18 [1-9])) // d {8} $"; return phonenumber.matches (regex); } / ** * Déterminez s'il s'agit d'un numéro de téléphone mobile * * @param phonenumber * numéro de téléphone mobile * @return boolean true, pass, false, a échoué * / public static boolean isphonenumber (String Phonenumber) {if (Strings.isnullloreMpty (phonenumber)) return false; String regex = "^ 1 // d {10} $"; return phonenumber.matches (regex); } / ** * Déterminez s'il contient des caractères spéciaux * * @param texte * @return booléen true, pass, false, échoué * / public static booléen hasspecialChar (texte de chaîne) {if (Strings.isnullorempty (texte)) return false; if (text.replaceAll ("[az] * [az] * // d * - * _ * // s *", "") .length () == 0) {// si les caractères spéciaux ne sont pas inclus return true; } return false; } Ischinese booléen statique privé (char c) {caractères.UnicodeBlock ub = caractères.UnicodeBlock.of (c); if (ub == caractères.unicodeblock.cjk_unified_ideographs || ub == caractères.unicodeblock.cjk_compatibilité_ideographie || ub == caractères.unicodeblock.cjk_unified_ideographs_extension_a || ub == caractères. Caractères.unicodeblock.cjk_symbols_and_punctuation || ub == caractères.unicodeblock.halfwidth_and_fullwidth_forms || ub == caractères.unicodeblock.general_punctuation) {return true; } return false; }}Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.