Hmm, regarding '\t' I guess you could use [\\s] like you did instead of mentioning space and newline explicitly (but as argument to split). As for merging the trimming and the splitting step, I think you shouldn't do that since as you can see then you have to do special cases for the beginning and end.