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();
}
What am I doing wrong? How comes the if statement never gets hit?
The
matches()method attempts to match the entire string to the pattern. You want thefind()method.