Compare commits

...

2 Commits

Author SHA1 Message Date
97e07db838 add ipv4,ipv5,domain regex 2026-01-13 17:40:50 +08:00
b070950ed6 add camelCaseClassName 2026-01-13 17:24:20 +08:00
2 changed files with 19 additions and 0 deletions

View File

@ -76,6 +76,15 @@ public class Regex {
/** 护照 */ /** 护照 */
public static final String PASSPORT = "^[a-zA-Z0-9]{5,17}$"; public static final String PASSPORT = "^[a-zA-Z0-9]{5,17}$";
// IPv4 正则表达式
public static final String IPv4 = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
// IPv6 正则表达式(简化版)
public static final String IPv6 = "^([0-9a-fA-F]{0,4}:){7}[0-9a-fA-F]{0,4}$|^::1$|^::$|^([0-9a-fA-F]{0,4}:){1,7}:$";
// 域名正则表达式RFC 1123
public static final String DOMAIN = "^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)*[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?$";
public static boolean isMatch(String regex, String text) { public static boolean isMatch(String regex, String text) {
if (TimiJava.isEmpty(regex) || TimiJava.isEmpty(text)) { if (TimiJava.isEmpty(regex) || TimiJava.isEmpty(text)) {
return false; return false;

View File

@ -390,4 +390,14 @@ public class Text {
} }
return sb.toString(); return sb.toString();
} }
/**
* 获取驼峰类名
*
* @param clazz 类
* @return 驼峰类名
*/
public static String camelCaseClassName(Class<?> clazz) {
return Character.toLowerCase(clazz.getSimpleName().charAt(0)) + clazz.getSimpleName().substring(1);
}
} }