Matching sentences with regex in Java

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-04-16T01:07:54Z Indexed on 2010/04/16 1:13 UTC
Read the original article Hit count: 463

Filed under:
|

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 :)

© Stack Overflow or respective owner

Related posts about java

Related posts about regex