Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java regex for any word

Tags:

java

regex

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+");
like image 879
HukeLau_DABA Avatar asked Oct 01 '22 07:10

HukeLau_DABA


1 Answers

try this

String[] words = line.split("\\W+");
like image 165
Evgeniy Dorofeev Avatar answered Oct 09 '22 17:10

Evgeniy Dorofeev