Having a sentence with multiple spaces by using regular expression I try to achieve the following:
example of sentence: This is a simple text.
Expected result:[This, is, a, simple, text.]
Actual result: [This, is, a, simple, text.]
ArrayList<String> tokens = new ArrayList<>();
Pattern tokSplitter = Pattern.compile("[a-zA-Z.*//s*]+");
Matcher m = tokSplitter.matcher("This is a simple text.");
while (m.find()) {
tokens.add(m.group());
}
System.out.println(tokens);