String str ="abc";
1.方案:str.matches(regex);
此方法调用的 str.matches(regex) 形式与以下表达式产生完全相同的结果:
Pattern.matches(regex, str)
matches源码:
2.方案:
3.两种方法比较:
// 匹配到子串
matcher.find()
// 刚好匹配到整串
matcher.matches()
1.方案:str.matches(regex);
此方法调用的 str.matches(regex) 形式与以下表达式产生完全相同的结果:
Pattern.matches(regex, str)
matches源码:
public static boolean matches(String regex, CharSequence input) {
//编译正则表达式
Pattern p = Pattern.compile(regex);
//是否匹配表达式
Matcher m = p.matcher(input);
2.方案:
Pattern titlePattern = Pattern.compile("(\\||`|<|>|\"|\')");
Matcher m = titlePattern.matcher(title);
if(!m.find())
3.两种方法比较:
// 匹配到子串
matcher.find()
// 刚好匹配到整串
matcher.matches()