I am trying to capture a certain number chunk from within a text. Suppose the text is Kane is 12345 feet high. I want to capture 12345. I am trying to use this:
import java.util.regex.Pattern;
import java.util.regex.Matcher;
String text = "Kane is 12345 feet high";
Pattern p = Pattern.compile("Kane is (\\d+) feet high");
Matcher m = p.matcher(text);
String s0 = m.group(0);
However I am getting a Match not found error. What am I doing wrong here? I mean, in Perl, this perfectly prints out 12345:
$foo = "Kane is 12345 feet high";
$foo =~ /Kane is (\d+) feet high/;
print $1;
matchesfor an exact match of the whole regex orfindto find the regex in a sub-string. Unfortunately it doesn't give you a more useful error likeMatch not found, did you forget to call matches() or find();)