|
|
|
@ -17,12 +17,17 @@ import java.util.regex.Pattern; |
|
|
|
@UtilityClass |
|
|
|
@UtilityClass |
|
|
|
public class PatternUtil { |
|
|
|
public class PatternUtil { |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern ID_CARD = Pattern.compile("\\d{17}[\\d|x|X]|\\d{15}"); |
|
|
|
private static final Pattern ID_CARD = Pattern.compile("\\d{17}[\\d|xX]|\\d{15}"); |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern MOBILE = Pattern.compile("^1(3|4|5|6|7|8|9)\\\\d{9}$"); |
|
|
|
private static final Pattern MOBILE = Pattern.compile("^1([3456789])\\\\d{9}$"); |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern MARK = Pattern.compile("1"); |
|
|
|
private static final Pattern MARK = Pattern.compile("1"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 正则表达式提取身份证 |
|
|
|
|
|
|
|
* @param content 内容 |
|
|
|
|
|
|
|
* @return 身份证,“,”分割 |
|
|
|
|
|
|
|
*/ |
|
|
|
public static String takeIdCard(String content) { |
|
|
|
public static String takeIdCard(String content) { |
|
|
|
StringBuilder str = new StringBuilder(); |
|
|
|
StringBuilder str = new StringBuilder(); |
|
|
|
if(content == null) { |
|
|
|
if(content == null) { |
|
|
|
@ -37,7 +42,11 @@ public class PatternUtil { |
|
|
|
} |
|
|
|
} |
|
|
|
return str.substring(0, str.length()-1); |
|
|
|
return str.substring(0, str.length()-1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 正则表达式提取手机号 |
|
|
|
|
|
|
|
* @param content 内容 |
|
|
|
|
|
|
|
* @return 手机号,“,”分割 |
|
|
|
|
|
|
|
*/ |
|
|
|
public static String takeMobile(String content) { |
|
|
|
public static String takeMobile(String content) { |
|
|
|
StringBuilder str = new StringBuilder(); |
|
|
|
StringBuilder str = new StringBuilder(); |
|
|
|
if(content == null) { |
|
|
|
if(content == null) { |
|
|
|
@ -53,6 +62,11 @@ public class PatternUtil { |
|
|
|
return str.substring(0, str.length()-1); |
|
|
|
return str.substring(0, str.length()-1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 提取1在字符串的所有位置 |
|
|
|
|
|
|
|
* @param content 内容 |
|
|
|
|
|
|
|
* @return 位置下标(1开始) |
|
|
|
|
|
|
|
*/ |
|
|
|
public static List<Integer> takeMarkPosition(String content) { |
|
|
|
public static List<Integer> takeMarkPosition(String content) { |
|
|
|
List<Integer> indexes = new ArrayList<>(); |
|
|
|
List<Integer> indexes = new ArrayList<>(); |
|
|
|
if(content == null) { |
|
|
|
if(content == null) { |
|
|
|
@ -65,6 +79,11 @@ public class PatternUtil { |
|
|
|
return indexes; |
|
|
|
return indexes; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 提取1在字符串的所有位置(返回字符串) |
|
|
|
|
|
|
|
* @param content 内容 |
|
|
|
|
|
|
|
* @return 位置下标(1开始,个位数补“0”) |
|
|
|
|
|
|
|
*/ |
|
|
|
public static List<String> takeMarkPositionToString(String content) { |
|
|
|
public static List<String> takeMarkPositionToString(String content) { |
|
|
|
List<String> indexes = new ArrayList<>(); |
|
|
|
List<String> indexes = new ArrayList<>(); |
|
|
|
if(content == null) { |
|
|
|
if(content == null) { |
|
|
|
|