类 RegexUtil


  • public class RegexUtil
    extends Object
    正则表达式工具类
    • 字段详细资料

      • REGEX_MOBILE_SIMPLE

        public static final String REGEX_MOBILE_SIMPLE
        简单手机号码正则表达式。
        另请参阅:
        常量字段值
      • REGEX_MOBILE_EXACT

        public static final String REGEX_MOBILE_EXACT
        确切的手机号码正则表达式。

        中国移动: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, 187, 188, 198

        中国联通: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186

        中国电信: 133, 153, 173, 177, 180, 181, 189, 199

        卫星电话: 1349

        虚拟运营商: 170

        另请参阅:
        常量字段值
      • REGEX_TEL

        public static final String REGEX_TEL
        电话号码的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_ID_CARD15

        public static final String REGEX_ID_CARD15
        身份证号码正则表达式,长度为15。
        另请参阅:
        常量字段值
      • REGEX_ID_CARD18

        public static final String REGEX_ID_CARD18
        身份证号码正则表达式,长度为18。
        另请参阅:
        常量字段值
      • REGEX_EMAIL

        public static final String REGEX_EMAIL
        电子邮件正则表达式。
        另请参阅:
        常量字段值
      • REGEX_URL

        public static final String REGEX_URL
        网址的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_USERNAME

        public static final String REGEX_USERNAME
        用户名的正则表达式。

        适用范围 "a-z", "A-Z", "0-9", "_", "汉字"

        不能以"_"结尾

        长度在6到20之间

        另请参阅:
        常量字段值
      • REGEX_DATE

        public static final String REGEX_DATE
        日期的正则表达式,其格式为“ yyyy-MM-dd”
        另请参阅:
        常量字段值
      • REGEX_IP

        public static final String REGEX_IP
        ip地址的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_DOUBLE_BYTE_CHAR

        public static final String REGEX_DOUBLE_BYTE_CHAR
        双字节字符的正则表达式(长度是两个字节(byte)的字符,比如“嗨”、“!”、“。”,汉字及中文标点就是双字节字符;“k”、“!”、“.”,英文字母及英文标点是单字节的。)。
        另请参阅:
        常量字段值
      • REGEX_BLANK_LINE

        public static final String REGEX_BLANK_LINE
        空行正则表达式。
        另请参阅:
        常量字段值
      • REGEX_QQ_NUM

        public static final String REGEX_QQ_NUM
        QQ号的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_CHINA_POSTAL_CODE

        public static final String REGEX_CHINA_POSTAL_CODE
        中国邮政编码正则表达式。
        另请参阅:
        常量字段值
      • REGEX_POSITIVE_INTEGER

        public static final String REGEX_POSITIVE_INTEGER
        正整数的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_NEGATIVE_INTEGER

        public static final String REGEX_NEGATIVE_INTEGER
        负整数的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_INTEGER

        public static final String REGEX_INTEGER
        整数的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_NOT_NEGATIVE_INTEGER

        public static final String REGEX_NOT_NEGATIVE_INTEGER
        非负整数的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_NOT_POSITIVE_INTEGER

        public static final String REGEX_NOT_POSITIVE_INTEGER
        非正整数的正则表达式。
        另请参阅:
        常量字段值
      • REGEX_POSITIVE_FLOAT

        public static final String REGEX_POSITIVE_FLOAT
        正浮点正则表达式。
        另请参阅:
        常量字段值
      • REGEX_NEGATIVE_FLOAT

        public static final String REGEX_NEGATIVE_FLOAT
        负浮点正则表达式。
        另请参阅:
        常量字段值
    • 方法详细资料

      • isMobileSimple

        public static boolean isMobileSimple​(CharSequence input)
        Return whether input matches regex of simple mobile.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isMobileExact

        public static boolean isMobileExact​(CharSequence input)
        Return whether input matches regex of exact mobile.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isTel

        public static boolean isTel​(CharSequence input)
        Return whether input matches regex of telephone number.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isIDCard15

        public static boolean isIDCard15​(CharSequence input)
        Return whether input matches regex of id card number which length is 15.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isIDCard18

        public static boolean isIDCard18​(CharSequence input)
        Return whether input matches regex of id card number which length is 18.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isEmail

        public static boolean isEmail​(CharSequence input)
        Return whether input matches regex of email.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isURL

        public static boolean isURL​(CharSequence input)
        Return whether input matches regex of url.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isZh

        public static boolean isZh​(CharSequence input)
        Return whether input matches regex of Chinese character.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isUsername

        public static boolean isUsername​(CharSequence input)
        Return whether input matches regex of username.

        scope for "a-z", "A-Z", "0-9", "_", "Chinese character"

        can't end with "_"

        length is between 6 to 20

        .
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isDate

        public static boolean isDate​(CharSequence input)
        Return whether input matches regex of date which pattern is "yyyy-MM-dd".
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isIP

        public static boolean isIP​(CharSequence input)
        Return whether input matches regex of ip address.
        参数:
        input - The input.
        返回:
        true: yes
        false: no
      • isMatch

        public static boolean isMatch​(String regex,
                                      CharSequence input)
        Return whether input matches the regex.
        参数:
        regex - The regex.
        input - The input.
        返回:
        true: yes
        false: no
      • getMatches

        public static List<String> getMatches​(String regex,
                                              CharSequence input)
        Return the list of input matches the regex.
        参数:
        regex - The regex.
        input - The input.
        返回:
        the list of input matches the regex
      • getSplits

        public static String[] getSplits​(String input,
                                         String regex)
        Splits input around matches of the regex.
        参数:
        input - The input.
        regex - The regex.
        返回:
        the array of strings computed by splitting input around matches of regex
      • getReplaceFirst

        public static String getReplaceFirst​(String input,
                                             String regex,
                                             String replacement)
        Replace the first subsequence of the input sequence that matches the regex with the given replacement string.
        参数:
        input - The input.
        regex - The regex.
        replacement - The replacement string.
        返回:
        the string constructed by replacing the first matching subsequence by the replacement string, substituting captured subsequences as needed
      • getReplaceAll

        public static String getReplaceAll​(String input,
                                           String regex,
                                           String replacement)
        Replace every subsequence of the input sequence that matches the pattern with the given replacement string.
        参数:
        input - The input.
        regex - The regex.
        replacement - The replacement string.
        返回:
        the string constructed by replacing each matching subsequence by the replacement string, substituting captured subsequences as needed