この記事は、参照用のJava正規表現ツールの特定のコードを共有しています。特定のコンテンツは次のとおりです
com.google.common.base.strings; Import java.util.regex.matcher; Import java.util.regex.pattern;/*** 2016/4/7にTakebraが作成した一般的に使用される正規表現*をインポートします。 */public class regexutils {/** *それが正しいIPアドレスであるかどうかを判断します * * @param ip * @return boolean true、pass、false、failed */public static boolean isip(string ip){if(strings.isnullrempty(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)$"; IP.Matchesを返す(Regex); } / ** *それが正しい電子メールアドレスであるかどうかを判断します * * @param email * @return boolean true、passed、false、faild * / public static boolean isemail(string email){if(strings.isnullorempty(email))return false; string regex = "//w+([ - +. ]//w+)*//w+(]] email.matches(regex)を返します。 } / ** *中国語が含まれているかどうかを判断します。句読点を含む中国文字にのみ適しています * @param Text * @return boolean true、passed、false、failed * / public static boolean ischinese(strings.isnullorempty(text))return false;パターンP = pattern.compile( "[/u4e00-/u9fa5]"); Matcher M = P.Matcher(テキスト); m.find()を返します。 } / ** *正の整数 * * @param number * number * @return boolean true、pass、false、failed * / public static boolean isnumber(string number){if(strings.isnullorempty(number))return false; string regex = "[0-9]*"; return number.matches(regex); } / ** * 10小数(正の数字) * * @param Decimal * number * @param count * @return boolean true、pass、false、falsed、failed * / public static boolean isdecimal(string.isnullorempty)return falseを決定します。 string regex = "^( - )?(([1-9] {1} // d*)|([0] {1}))(//。(// d){" + count + "})?$"; return decimal.matches(regex); } / ** *それが携帯電話番号であるかどうかを判断します * * @Param PhoneNumber *携帯電話番号 * @return boolean true、pass、false、failed * / public volean ismobilephoneNumber(String.isnullorempty(PhoneNumber))return false; string regex = "^((13 [0-9])|(15 [0-9])|(18 [1-9]))// d {8} $"; return phoneNumber.matches(regex); } / ** *携帯電話番号であるかどうかを判断します * * @param PhoneNumber *携帯電話番号 * @return Boolean True、Pass、False、Failed * / public static Boolean isphoneNumber(String PhoneNumber){if(strings.isnullorempty(ShoneNumber))return false; string regex = "^1 // d {10} $"; return phoneNumber.matches(regex); } / ** *特殊文字が含まれているかどうかを判断します * * @param Text * @return boolean true、pass、false、faild * / public static boolean hasspecialchar(string text){if(strings.isnullorempty(text))return false; if(text.replaceall( "[az]*[az]*// d* - *_*// s*"、 "").length()== 0){//特殊文字が含まれていない場合、trueを返します。 } falseを返します。 } private static boolean ischinese(char c){character.unicodeblock ub = character.unicodeblock.of(c); if(ub == character.unicodeblock.cjk_unified_ideographs || ub == character.unicodeblock.cjk_compatibility_ideographss || ub == character.unicodeblock.cjk_unifided_ideagraphgraghtographs_extension_a || ub == charital.unicodedifidifided_idegographion Chariture.unicodeBlock.cjk_symbols_and_punctuation ||。 } falseを返します。 }}上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。