Java regex
W
It matches any non-word character like * or # or whatever. It can be used with other methods like
//paragraph = "Bob hit a ball, the hit BALL flew far after it was hit."
String[] words = p.toLowerCase().split("\\W+");
s
It matches any whitespace character. We can use with .split() to split string via whitespaces like:
String str = "Hello, World!";
String[] words = str.split("\\s+");
//Hello,
//World!
.replaceAll()
It replaces the pattern passed as first parameter with the second pattern parameter.
//set * at index i
sb.setCharAt(i,'*');
//replaces all * with non-white space
sb.toString().replaceAll("\\*","");