Java split a string by space, new line, tab, punctuation

java, string

Solution

You can do

String[] dic = message.split("\\W+");

The `\\W` means not an alphanumeric character.

Problem

everyone. I have a string like this ``` String message = "This is the new message or something like that, OK"; ``` And I want to split it into array ``` String[] dic = {"this", "is", "the", "new", "message", "or", "something", "like", "that", "OK"}; ``` I used ``` message = message.split("\\s+"); ``` The problem was that it contained "that," not "that" like I want. Please teach my how to solve it. Thanks

Original source

Related problems