1String s = "This is a sample sentence.";
2String[] words = s.split("\\s+");
3for (int i = 0; i < words.length; i++) {
4 // You may want to check for a non-word character before blindly
5 // performing a replacement
6 // It may also be necessary to adjust the character class
7 words[i] = words[i].replaceAll("[^\\w]", "");
8}