Splitting text by whitespaces headache š¤š„
Hello learners!! If somebody can help.... ā Why String#split or Pattern#split return one result more on empty string or with trailing whitespaces? š¤š¤š¤ "".split("\\s+").length == 1 " ".split("\\s+").length == 0 " Hello learners".split("\\s+").length == 3 " Hello learners ".split("\\s+").length == 3 ā There are any regex to solve it? I mean, some using non capture groups or look ahead/behind capture modifiers combination to bypass it. I try it but without success š„. E.g.: (?:^\\s+)\\s+ https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/regex/Pattern.html At this moment I hack it doing a trim() before but I wish know other options... mastering on regular expressions. Testcase Template š https://code.sololearn.com/ckmNb74UCnqr/?ref=app Where I want to apply it š https://code.sololearn.com/cd7dRTk2331T/?ref=app