fix regex bug

change the regex to a js trim function. regex was eating up the ending
words if there was no white space. Trim function cleans front and end of
white space.