Right now my code only separates words by white space, but I also want to separate by '.' and "," too. Here is my current code:
for (String words : input.split("\\s+"))
For example, if the user entered "bread,milk,eggs" or "Um...awkss" It would consider that one word, and I want each word to be it's own word.
And while I'm here, I can't get
input.isAlpha()
to work either.
You can split using this regex
input.split("\\s+|.+|,+")
or simply:
input.split("[\\s.,]+")
Remember that a dot doesn't have to be escaped inside square brackets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With