Regex to split a string (in Java) so that spaces are preserved?

Posted by david on Stack Overflow See other posts from Stack Overflow or by david
Published on 2010-06-02T19:52:22Z Indexed on 2010/06/02 19:54 UTC
Read the original article Hit count: 163

Filed under:
|
|
|

I need to split a string (in Java) into individual words ... but I need to preserve spaces.

An example of the text I need to split is something like this:
ABC . . . . DEF . . . . GHI

I need to see "ABC", " . . . .", "DEF", ". . . .", and "GHI".

Obviously splitting on the space character \s isn't going to work, as all the spaces get swallowed up as one space.

Any suggestions?

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about regex