public class RegexUtil {
/**
* 返回所有匹配到的内容
*
* @param regex 正则表达式字符串
* @param str 要匹配的字符串
* @return
*/
public static List group(String str, String regex) {
if (null == str || null == regex) {
return null;
}
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
List list = new LinkedList();
while (matcher.find()) {
list.add(matcher.group());
}
return list;
}
/**
* 存在匹配
*
* @param str
* @param regex
* @return
*/
private static boolean find(String str, String regex) {
if (null == str || str.trim().length()
关注
打赏
正则表达式工具类
立即登录/注册


微信扫码登录