haven\'t really tried it but I believe the general idea is as follows:
import java.util.regex.*;
Pattern p = Pattern.compile(\"the \\w{3}\");
Matcher m = p.matcher(“the quick brown fox jumped over the lazy dogs.”);
while (m.find())
{
// print out m.start(); // this is the index
// print out m.toString(); // this should be the matched string
}
it\'s a much efficient way; however, there is also a simpler way, which is to just use indexOf to continue finding \"the \", blab blab blab.
pattern不只是一个,有很多个,比如
Examining line: \'the quick brown fox jumped over the lazy dogs.\' for pattern: \'the ???\'
Found \'the qui\' at position 0
Found \'the laz\' at position 32
Examining line: \'abba is a band not from norway at all\' for pattern: \'a??a\'
Found \'abba\' at position 0
Found \'a ba\' at position 8
Found \'ay a\' at position 28
Found \'at a\' at position 31