Artikel ini telah membagikan kode spesifik alat ekspresi reguler Java untuk referensi Anda. Konten spesifiknya adalah sebagai berikut
impor com.google.common.base.strings; impor java.util.regex.matcher; import java.util.regex.pattern;/*** Umumnya digunakan ekspresi reguler* dibuat oleh TakeBra pada 2016/4/7. */Regexutils kelas publik {/** * Tentukan apakah itu adalah alamat IP yang benar * * @param ip * @return boolean true, pass, false, fag */public static boolean isip (string ip) {if (string.isnullorempty (ip)) mengembalikan 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); } / ** * Tentukan apakah itu alamat email yang benar * * @param email * @return boolean true, lulus, false, gagal * / public static boolean isemail (email string) {if (string.isnullorEmpty (email)) kembalikan false; String regex = "//w+(uarkan-+. kembalikan email.matches (regex); } / ** * Tentukan apakah itu berisi bahasa Cina, hanya cocok untuk karakter Cina, tidak termasuk tanda baca * @param text * @return boolean true, lulus, false, gagal * / public static boolean ischinese (string text) {if (string.isnullorempty (teks)) mengembalikan palsu; Pola p = pola.compile ("[/u4e00-/u9fa5]"); Pencocokan m = p.matcher (teks); return m.find (); } / ** * Tentukan apakah bilangan bulat positif * * @param nomor * nomor * @return boolean true, pass, false, gagal * / public static boolean isNumber (nomor string) {if (string.isnullorempty (angka)) return false; String regex = "[0-9]*"; return number.matches (regex); } / ** * Tentukan berapa banyak desimal (angka positif) * * @param desimal * angka * @param count * digit desimal * @return boolean true, pass, false, fag * / public static boolean isDecimal (string desimal, int count) {if (string.isnullorempty (desimal) retrect; String regex = "^(-)? (([1-9] {1} // d*) | ([0] {1})) (//. (// d) {" + count + "})? $"; return decimal.matches (regex); } / ** * Tentukan apakah itu nomor ponsel * * @param phonenumber * Nomor ponsel * @return boolean true, pass, false, fag * / public static boolean ismobilephonenumber (bilangan fonenumber) {if (string.isnullorempty (phoneneNumber)) return false; String regex = "^((13 [0-9]) | (15 [0-9]) | (18 [1-9])) // d {8} $"; return phonenumber.matches (regex); } / ** * Tentukan apakah itu nomor ponsel * * @param phonenumber * Nomor telepon seluler * @return boolean true, pass, false, gagal * / public static boolean isphonenumber (string phonenumber) {if (string.isnullorempty (phoneNumber)) mengembalikan false; String regex = "^1 // d {10} $"; return phonenumber.matches (regex); } / ** * Tentukan apakah itu berisi karakter khusus * * @param text * @return boolean true, pass, false, fag * / public static boolean hasspecialchar (string text) {if (string.isnullorempty (teks)) mengembalikan false; if (text.replaceall ("[az]*[az]*// d*-*_*// s*", "") .length () == 0) {// Jika karakter khusus tidak termasuk return true; } return false; } private static boolean ischinese (char c) {karakter.unicodeBlock ub = karakter.unicodeBlock.of (c); if (ub == character.unicodeBlock.cjk_unified_ideographs || ub == karakter.unicodeBlock.cjk_compatibility_ideographs || uB == karakter.unicodeBlock.cjk_unified_ideographs_extension_a || ub == karakter.unicodeBlock.idePrographs_extension_a || UB == karakter.unicodeBlock.cjographs_Iphographs_Uxtension_a || uB == karakter.unicodeBlock.cjographs_Iphographs_Uxtensione || uB == character.unicodeBlock.cjographs_ideographs_Urographs_uniFiFicer Character.unicodeBlock.cjk_symbols_and_punction ||. } return false; }}Di atas adalah semua konten artikel ini. Saya berharap ini akan membantu untuk pembelajaran semua orang dan saya harap semua orang akan lebih mendukung wulin.com.