String url = "hello world";
String p = "world";
Pattern pattern = Pattern.compile(p);
Matcher matcher = pattern.matcher(url);
if (matcher.matches()) {
int start = matcher.start();
int end = matcher.end();
}
我在做什么错? if语句怎么会不被打到?愚蠢的RegEx问题。我究竟做错了什么?
或“String p =”\ * world \ *“; –
您是对的,谢谢,我阅读了Matcher上的文档,我仍然不清楚match()和find()之间的区别。你介意详细说明一下? – user123321
匹配表示“整个字符串是否与提供的模式匹配”。查找的意思是“字符串内是否有这种模式出现” –