You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.6 KiB
94 lines
2.6 KiB
package com.bfd.operate.utils;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import java.security.MessageDigest;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* @author jinming
|
|
* @version 1.0
|
|
* @className StringUtile
|
|
* @Date 2022/1/21 11:46
|
|
*/
|
|
@Slf4j
|
|
public class StringUtil {
|
|
public static boolean hasValue(String str) {
|
|
return str != null && !"".equals(str.trim());
|
|
}
|
|
|
|
public static String getRegexGroup(String regex, String str, int id) {
|
|
String resultStr = "";
|
|
if (hasValue(str)) {
|
|
Pattern p = Pattern.compile(regex);
|
|
Matcher m = p.matcher(str);
|
|
if (m.find()) {
|
|
resultStr = m.group(id);
|
|
}
|
|
}
|
|
|
|
if ("".equals(resultStr)) {
|
|
}
|
|
|
|
return resultStr;
|
|
}
|
|
|
|
public static Set<String> getEmailAddress(String message) {
|
|
Set<String> emailList = new HashSet<>();
|
|
Pattern pattern = Pattern.compile("\\w+\\.?\\w+\\@\\w+\\.\\w+");
|
|
Matcher m = pattern.matcher(message);
|
|
while (m.find()) {
|
|
emailList.add(m.group(0));
|
|
}
|
|
return emailList;
|
|
}
|
|
public static String getMd5(String string) {
|
|
try {
|
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
byte[] bs = md5.digest(string.getBytes("UTF-8"));
|
|
StringBuilder sb = new StringBuilder(40);
|
|
for (byte x : bs) {
|
|
if ((x & 0xff) >> 4 == 0) {
|
|
sb.append("0").append(Integer.toHexString(x & 0xff));
|
|
} else {
|
|
sb.append(Integer.toHexString(x & 0xff));
|
|
}
|
|
}
|
|
return sb.toString();
|
|
} catch (Exception e) {
|
|
//LOG.error("获取md5异常", e);
|
|
return "nceaform" + System.currentTimeMillis();
|
|
}
|
|
}
|
|
|
|
public static String removeAllHtmlTags(String str) {
|
|
return hasValue(str) ? str.replaceAll("<[^<>]+?>", "") : "";
|
|
}
|
|
|
|
public static String getRegexGroup(Pattern regex, String str, int id) {
|
|
String resultStr = "";
|
|
if (hasValue(str)) {
|
|
Matcher m = regex.matcher(str);
|
|
if (m.find()) {
|
|
resultStr = m.group(id);
|
|
}
|
|
}
|
|
|
|
if ("".equals(resultStr)) {
|
|
log.error(regex + " parser error!");
|
|
}
|
|
|
|
return resultStr;
|
|
}
|
|
|
|
public static String getStrByPattern(String str, String regex) {
|
|
Pattern pattern = Pattern.compile(regex);
|
|
Matcher m = pattern.matcher(str);
|
|
return m.find() ? m.group(0) : "";
|
|
}
|
|
|
|
}
|