Este artigo compartilhou o código específico da ferramenta de expressão regular Java para sua referência. O conteúdo específico é o seguinte
importar com.google.common.base.strings; importar java.util.regex.matcher; importar java.util.regex.pattern;/*** Expressões regulares comumente usadas* criadas por TakenBra em 2016/4/7. */classe pública regexutils {/** * Determine se é o endereço IP correto * * @param ip * @return boolean true, passa, false, falhado */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) $"; retornar ip.matches (regex); } / ** * Determine se é o endereço de email correto * * @param email * @return boolean true, aprovado, false, falhado * / public estático boolean isEmail (string email) {if (strings.isnullorEmpty (email)) retornar false; String regex = "//w+([-+.bors//w+)*@//w+([-.bor retornar email.matches (regex); } / ** * Determine se ele contém chinês, adequado apenas para caracteres chineses, sem incluir pontuação * @param texto * @return boolean verdadeiro, aprovado, falso, falhado * / public static boolean ischinese (text string) {if (strings.isnullorEmpty (text)) retornar false; Padrão p = padrão.compile ("[/u4e00-/u9fa5]"); Matcher M = P.Matcher (texto); retornar m.find (); } / ** * Determine se um número inteiro positivo * * @param número * número * @return boolean true, passa, falso, falhado * / public static boolean isNumber (número da string) {if (strings.isnullorEmpty (número)) retornar false; String regex = "[0-9]*"; retorno número.Matches (regex); } / ** * Determine quantos decimais (números positivos) * * @param decimal * número * @param count * dígitos decimais * @return boolean true, passa, false, falhado * / public static boolean isDecimal (string decimal, int conting) {if (strings.isnullorEmpty (decimal)) Retorno; String regex = "^(-)? (([1-9] {1} // d*) | ([0] {1})) (//. (// d) {" + count + "})? $"; retornar decimal.Matches (regex); } / ** * Determine se é um número de telefone celular * * @param phoneNumber * número de telefone celular * @return boolean true, passa, false, falhado * / public estático booleano ismobilepneneNumber (string foneNumber) {if (strings.isnullorEmpty (phoneNumber)) return; String regex = "^((13 [0-9]) | (15 [0-9]) | (18 [1-9])) // d {8} $"; return phoneNumber.matches (regex); } / ** * Determine se é um número de telefone celular * * @param phoneNumber * número de telefone celular * @return boolean true, passa, false, falhado * / public static boolean isphoneNumber (string phoneNumber) {if (strings.isnullorEmpty (phoneNumber)) retornar falso; String regex = "^1 // d {10} $"; return phoneNumber.matches (regex); } / ** * Determine se ele contém caracteres especiais * * @param texto * @return boolean true, passa, false, falhado * / public estático booleano hasspecialchar (text string) {if (strings.isnullorEmpty (text)) retornar false; if (text.ReplaceAll ("[az]*[az]*// d*-*_*// s*", "") .Length () == 0) {// Se os caracteres especiais não estiverem incluídos retornar true; } retornar false; } private estático booleano isquineso (char c) {caractere.unicodeblock ub = caractere.unicodeblock.of (c); if (ub == caractere.unicodeblock.cjk_unified_ideographs || ub == caractere.unicodeblock.cjk_compatibility_ideographs || ub == caractere.unicodeblock.cjk_unified_ideographs_extension_anied ||semext.enicodblock.cjk_unified_ideografs_extension_a | Caractere.unicodeblock.cjk_symbols_and_punction ||. } retornar false; }}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.