TextUtil.java
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cn.com.glsx.entmicro.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Author yelq
* @Version 1.0
* @Description:
* @Date 2022/1/15 12:42
*/
public class TextUtil {
//车牌截取
public static String carNumberSubstring(String carnNmber) {
if (carnNmber == null) {
return null;
}
String reg = "[京津沪渝冀吉辽黑湘鄂甘晋陕豫川云桂蒙贵青藏新宁粤琼闽苏浙赣鲁皖]";
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(carnNmber);
if (m.find()) {
return carnNmber.substring(m.start());
}
return carnNmber;
}
/**
* 过滤出中文、数字、字母
*
* @param str
* @return
*/
public static String stringFilterCharaterAndNumber(String str) {
if (str == null || str.isEmpty()) {
return str;
}
//\u005f 代表"_"
return str.replaceAll("[^(a-zA-Z0-9\\u4e00-\\u9fa5)]", "").replace("(","").replace(")","").trim();
}
}