replace trim() with regex

Optimizes some string ops to use regex where ever possible based on http://jsperf.com/exec-vs-match-vs-test-vs-search/5

* optimizes string.trim() calls with regex.test()
* optimizes string.lastIndexOf() calls with regex.search()

@redmunds can you review?
/cc:@RaymondLim