Matching sentences with regex in Java
- by Gary
Hi, I'm using the Scanner class in java to go through a a text file and extract each sentence. I'm using the setDelimiter method on my Scanner to the regex:
Pattern.compile("[\\w]*[\\.|?|!][\\s]")
This currently seems to work, but it leaves the whitespace at the end of the sentence. Is there an easy way to match the whitespace at the end but not include it in the result?
I realize this is probably an easy question but I've never used regex before so go easy :)