mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bugf
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.hutool.core.lang;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.regex.PatternPool;
|
||||
import cn.hutool.core.regex.RegexPool;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.CreditCodeUtil;
|
||||
import cn.hutool.core.math.NumberUtil;
|
||||
@@ -915,7 +916,7 @@ public class Validator {
|
||||
* @since 5.2.1
|
||||
*/
|
||||
public static boolean hasChinese(final CharSequence value) {
|
||||
return ReUtil.contains(ReUtil.RE_CHINESES, value);
|
||||
return ReUtil.contains(RegexPool.CHINESES, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -33,15 +33,6 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class ReUtil {
|
||||
|
||||
/**
|
||||
* 正则表达式匹配中文汉字
|
||||
*/
|
||||
public final static String RE_CHINESE = RegexPool.CHINESE;
|
||||
/**
|
||||
* 正则表达式匹配中文字符串
|
||||
*/
|
||||
public final static String RE_CHINESES = RegexPool.CHINESES;
|
||||
|
||||
/**
|
||||
* 正则中需要被转义的关键字
|
||||
*/
|
||||
@@ -459,7 +450,7 @@ public class ReUtil {
|
||||
* @return 删除后剩余的内容
|
||||
*/
|
||||
public static String delAll(final String regex, final CharSequence content) {
|
||||
if (StrUtil.hasBlank(regex, content)) {
|
||||
if (StrUtil.hasEmpty(regex, content)) {
|
||||
return StrUtil.str(content);
|
||||
}
|
||||
|
||||
@@ -475,7 +466,7 @@ public class ReUtil {
|
||||
* @return 删除后剩余的内容
|
||||
*/
|
||||
public static String delAll(final Pattern pattern, final CharSequence content) {
|
||||
if (null == pattern || StrUtil.isBlank(content)) {
|
||||
if (null == pattern || StrUtil.isEmpty(content)) {
|
||||
return StrUtil.str(content);
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@ import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ReUtilTest {
|
||||
|
||||
static final String content = "ZZZaaabbbccc中文1234";
|
||||
|
||||
@Test
|
||||
@@ -56,6 +57,7 @@ public class ReUtilTest {
|
||||
Assert.assertEquals("公斤",ReUtil.delLast("\\d+", word));
|
||||
Assert.assertEquals("公斤",ReUtil.delLast(PatternPool.NUMBERS, word));
|
||||
//去除汉字
|
||||
//noinspection UnnecessaryUnicodeEscape
|
||||
Assert.assertEquals("180",ReUtil.delLast("[\u4E00-\u9FFF]+", word));
|
||||
Assert.assertEquals("180",ReUtil.delLast(PatternPool.CHINESES, word));
|
||||
|
||||
@@ -66,6 +68,7 @@ public class ReUtilTest {
|
||||
Assert.assertEquals("10.商品KLS100021型号xxl适合身高180体重斤的用户", s);
|
||||
|
||||
//多个匹配删除最后一个 判断是否不在包含最后的数字
|
||||
//noinspection UnnecessaryUnicodeEscape
|
||||
Assert.assertFalse(ReUtil.delLast("[\u4E00-\u9FFF]+", sentence).contains("斤的用户"));
|
||||
Assert.assertFalse(ReUtil.delLast(PatternPool.CHINESES, sentence).contains("斤的用户"));
|
||||
}
|
||||
@@ -96,6 +99,7 @@ public class ReUtilTest {
|
||||
@Test
|
||||
public void isMatchTest() {
|
||||
// 给定字符串是否匹配给定正则
|
||||
//noinspection UnnecessaryUnicodeEscape
|
||||
final boolean isMatch = ReUtil.isMatch("\\w+[\u4E00-\u9FFF]+\\d+", content);
|
||||
Assert.assertTrue(isMatch);
|
||||
}
|
||||
@@ -227,4 +231,9 @@ public class ReUtilTest {
|
||||
final String s = ReUtil.replaceAll("1.2.3.4", patternIp, "$1.**.**.$10");
|
||||
Assert.assertEquals("1.**.**.4", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issueI6GIMTTest(){
|
||||
Assert.assertEquals(StrUtil.EMPTY, ReUtil.delAll("[\\s]*", " "));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user