I am trying to split each string from a paragraph, which has proper grammar based punctuation delimiters like ,.!? or more if any.
I am trying to achieve this using Java. Here is my code.
private void printWords(String inputString) {
String[] x = inputString.split("[.!,\\s]");
for(String temp: x){
System.out.println(temp);
}
}
Sample input String:
He is srk. Oh! I am a very good friend of srk.
My output:
He
is
srk
Oh
I
am
a
very
good
friend
of
srk
There is a problem here, It is having spaces as shown in the output. What should be my regular expression to split strings in any given paragraph, without spaces in the output.