I use the following code to extract the age of a user in one document, but his age appears several times:
Pattern r = Pattern.compile("(\\d{2})(?=-year-old)");
Matcher matcher = r.matcher("He is a 55-year-old doctor. xxxxx. As a 55-year-old man he xxxx. When he is 55-year-old , xxxx");
if(matcher.find()) {
System.out.println(matcher.group(0));
}
Finally I get the result:
55
55
55
How can I just print 55
once?
Thanks in advance.