Improved the trim function to use a regexp function to catch more whitespace types