replaced trim with regex for older browsers