Splitting a string into words and punctuation with java

java, regex, string

Solution

You can do it using `regex` as follows:

String d = Str.split("\\W+");

Updated answer for your question:

String d = Str.split("\\b");

Problem

I'm trying to split a string up into words and punctuation, adding the punctuation to the list produced by the split. For instance: `String c = "help, me!"` I want out the list to look like is: `['help', ',', 'me', '!']` So, I want the string split at whitespace with the punctuation split from the words. Do you have ideas how to do it?

Original source