Setting up Matcher for String phrase match in file

Posted by randomCoder on Stack Overflow See other posts from Stack Overflow or by randomCoder
Published on 2011-03-16T08:01:06Z Indexed on 2011/03/16 8:10 UTC
Read the original article Hit count: 218

Filed under:
|
|
|

Having trouble figuring out how to match a phrase string to a phrase in file stream. The file I'm dealing with contains random words such as:

3 little pigs built houses and 1 little pig went to the market etc. for many lines

Using "little pig" as my pattern and matcher.find() I can locate 2 matches: "little pig" and "little pigs". However, I only want it to match "little pig".

What can I do? I thought about using matcher.lookingAt() but I wouldn't know how to set a proper region when I can't rely on the file string phrases I'm matching being on separate lines.

© Stack Overflow or respective owner

Related posts about java

Related posts about file