April 2019
Beginner to intermediate
386 pages
11h 20m
English
We can also determine the position of an entity in the sample text using the start and end methods, as shown next. These represent the beginning and ending indexes in the target string. The matcher is reinitialized using the sample text. This is necessary because the Matcher instance has exhausted the string, and there are no more entities to be found. The while loop iterates through the text displaying each entity along with its beginning and ending positions within the text:
matcher = pattern.matcher(sampleText);while (matcher.find()) { System.out.println(matcher.group() + " [" + matcher.start() + ":" + matcher.end() + "]");}
Execute the previous example. You will get the following output:
nlp@nlpworks.com [29:45]mrnlp@nlpworks.org ...
Read now
Unlock full access