2022-12-10 23:16:04 +08:00
|
|
|
package xyz.zhouxy.plusone.util;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
2023-02-18 11:58:06 +08:00
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
|
|
|
|
2022-12-10 23:16:04 +08:00
|
|
|
public class RegexUtil {
|
|
|
|
|
|
2023-02-18 11:58:06 +08:00
|
|
|
public static boolean matches(CharSequence input, String regex) {
|
|
|
|
|
return ReUtil.isMatch(regex, input);
|
2022-12-10 23:16:04 +08:00
|
|
|
}
|
|
|
|
|
|
2023-02-18 11:58:06 +08:00
|
|
|
public static boolean matches(CharSequence input, Pattern regex) {
|
|
|
|
|
return ReUtil.isMatch(regex, input);
|
2022-12-10 23:16:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean matchesOr(CharSequence input, String... regexs) {
|
|
|
|
|
boolean isMatched;
|
|
|
|
|
for (String regex : regexs) {
|
2023-02-18 11:58:06 +08:00
|
|
|
isMatched = matches(input, regex);
|
|
|
|
|
if (isMatched) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean matchesOr(CharSequence input, Pattern... regexs) {
|
|
|
|
|
boolean isMatched;
|
|
|
|
|
for (Pattern regex : regexs) {
|
|
|
|
|
isMatched = matches(input, regex);
|
2022-12-10 23:16:04 +08:00
|
|
|
if (isMatched) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean matchesAnd(CharSequence input, String... regexs) {
|
|
|
|
|
boolean isMatched;
|
|
|
|
|
for (String regex : regexs) {
|
2023-02-18 11:58:06 +08:00
|
|
|
isMatched = matches(input, regex);
|
2022-12-10 23:16:04 +08:00
|
|
|
if (!isMatched) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-02-18 11:58:06 +08:00
|
|
|
|
|
|
|
|
public static boolean matchesAnd(CharSequence input, Pattern... regexs) {
|
|
|
|
|
boolean isMatched;
|
|
|
|
|
for (Pattern regex : regexs) {
|
|
|
|
|
isMatched = matches(input, regex);
|
|
|
|
|
if (!isMatched) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RegexUtil() {
|
|
|
|
|
throw new IllegalStateException("Utility class");
|
|
|
|
|
}
|
2022-12-10 23:16:04 +08:00
|
|
|
}
|