HukeLau_DABA
HukeLau_DABA

Reputation: 2526

java regex for any word

im trying to figure out the regex to use to split an essay into words WITHOUT punctuation. I tried splitting by whitespace, but that gives some tokens with the punctuation. I also tried to split by word chars, which returned an array of empty strings for some reason:

String[] words = line.split("\\w+");

Upvotes: 5

Views: 10553

Answers (1)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 135992

try this

String[] words = line.split("\\W+");

Upvotes: 4

Related Questions