I have found the following solution from a similar question. Here is the link:
Find pattern in files with java 8
Pattern p = Pattern.compile("is '(.+)'");
stream1.map(p::matcher)
.filter(Matcher::matches)
.findFirst()
.ifPresent(matcher -> System.out.println(matcher.group(1)));
This is the solution given by khelwood. This is very useful to me. But I don't know why it is not printing anything.
I am trying to match anything that follows the word 'is '.
And my input file contains these lines:
my name is tom
my dog is hom.
I need to print
tom
hom.
But nothing is printed