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