类 RegexUtil
- java.lang.Object
-
- net.risesoft.api.utils.RegexUtil
-
public class RegexUtil extends Object
正则表达式工具类
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringREGEX_BLANK_LINE空行正则表达式。static StringREGEX_CHINA_POSTAL_CODE中国邮政编码正则表达式。static StringREGEX_DATE日期的正则表达式,其格式为“ yyyy-MM-dd”static StringREGEX_DOUBLE_BYTE_CHAR双字节字符的正则表达式(长度是两个字节(byte)的字符,比如“嗨”、“!”static StringREGEX_EMAIL电子邮件正则表达式。static StringREGEX_ID_CARD15身份证号码正则表达式,长度为15。static StringREGEX_ID_CARD18身份证号码正则表达式,长度为18。static StringREGEX_INTEGER整数的正则表达式。static StringREGEX_IPip地址的正则表达式。static StringREGEX_MOBILE_EXACT确切的手机号码正则表达式。static StringREGEX_MOBILE_SIMPLE简单手机号码正则表达式。static StringREGEX_NEGATIVE_FLOAT负浮点正则表达式。static StringREGEX_NEGATIVE_INTEGER负整数的正则表达式。static StringREGEX_NOT_NEGATIVE_INTEGER非负整数的正则表达式。static StringREGEX_NOT_POSITIVE_INTEGER非正整数的正则表达式。static StringREGEX_POSITIVE_FLOAT正浮点正则表达式。static StringREGEX_POSITIVE_INTEGER正整数的正则表达式。static StringREGEX_QQ_NUMQQ号的正则表达式。static StringREGEX_TEL电话号码的正则表达式。static StringREGEX_URL网址的正则表达式。static StringREGEX_USERNAME用户名的正则表达式。static StringREGEX_ZH汉字正则表达式。
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static List<String>getMatches(String regex, CharSequence input)Return the list of input matches the regex.static StringgetReplaceAll(String input, String regex, String replacement)Replace every subsequence of the input sequence that matches the pattern with the given replacement string.static StringgetReplaceFirst(String input, String regex, String replacement)Replace the first subsequence of the input sequence that matches the regex with the given replacement string.static String[]getSplits(String input, String regex)Splits input around matches of the regex.static booleanisDate(CharSequence input)Return whether input matches regex of date which pattern is "yyyy-MM-dd".static booleanisEmail(CharSequence input)Return whether input matches regex of email.static booleanisIDCard15(CharSequence input)Return whether input matches regex of id card number which length is 15.static booleanisIDCard18(CharSequence input)Return whether input matches regex of id card number which length is 18.static booleanisIP(CharSequence input)Return whether input matches regex of ip address.static booleanisMatch(String regex, CharSequence input)Return whether input matches the regex.static booleanisMobileExact(CharSequence input)Return whether input matches regex of exact mobile.static booleanisMobileSimple(CharSequence input)Return whether input matches regex of simple mobile.static booleanisTel(CharSequence input)Return whether input matches regex of telephone number.static booleanisURL(CharSequence input)Return whether input matches regex of url.static booleanisUsername(CharSequence input)Return whether input matches regex of username.static booleanisZh(CharSequence input)Return whether input matches regex of Chinese character.
-
-
-
字段详细资料
-
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_USERNAME
public static final String REGEX_USERNAME
用户名的正则表达式。适用范围 "a-z", "A-Z", "0-9", "_", "汉字"
不能以"_"结尾
长度在6到20之间
- 另请参阅:
- 常量字段值
-
REGEX_DOUBLE_BYTE_CHAR
public static final String REGEX_DOUBLE_BYTE_CHAR
双字节字符的正则表达式(长度是两个字节(byte)的字符,比如“嗨”、“!”、“。”,汉字及中文标点就是双字节字符;“k”、“!”、“.”,英文字母及英文标点是单字节的。)。- 另请参阅:
- 常量字段值
-
REGEX_NOT_NEGATIVE_INTEGER
public static final String REGEX_NOT_NEGATIVE_INTEGER
非负整数的正则表达式。- 另请参阅:
- 常量字段值
-
REGEX_NOT_POSITIVE_INTEGER
public static final String REGEX_NOT_POSITIVE_INTEGER
非正整数的正则表达式。- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
isMobileSimple
public static boolean isMobileSimple(CharSequence input)
Return whether input matches regex of simple mobile.- 参数:
input- The input.- 返回:
true: yesfalse: no
-
isMobileExact
public static boolean isMobileExact(CharSequence input)
Return whether input matches regex of exact mobile.- 参数:
input- The input.- 返回:
true: yesfalse: no
-
isTel
public static boolean isTel(CharSequence input)
Return whether input matches regex of telephone number.- 参数:
input- The input.- 返回:
true: yesfalse: 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: yesfalse: 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: yesfalse: no
-
isEmail
public static boolean isEmail(CharSequence input)
Return whether input matches regex of email.- 参数:
input- The input.- 返回:
true: yesfalse: no
-
isURL
public static boolean isURL(CharSequence input)
Return whether input matches regex of url.- 参数:
input- The input.- 返回:
true: yesfalse: no
-
isZh
public static boolean isZh(CharSequence input)
Return whether input matches regex of Chinese character.- 参数:
input- The input.- 返回:
true: yesfalse: 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: yesfalse: 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: yesfalse: no
-
isIP
public static boolean isIP(CharSequence input)
Return whether input matches regex of ip address.- 参数:
input- The input.- 返回:
true: yesfalse: no
-
isMatch
public static boolean isMatch(String regex, CharSequence input)
Return whether input matches the regex.- 参数:
regex- The regex.input- The input.- 返回:
true: yesfalse: 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
-
-