Is there any library API or regex pattern to split a String on some delimiter and automatically trim leading and trailing spaces from every element without having to loop the el
What about just doing a replaceall before splitting?
str.replaceall("\\s*#\\s*","#").split()