Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created August 5, 2015 00:38
Show Gist options
  • Select an option

  • Save JavaScript-Packer/a1e9d7bd12076e6e1503 to your computer and use it in GitHub Desktop.

Select an option

Save JavaScript-Packer/a1e9d7bd12076e6e1503 to your computer and use it in GitHub Desktop.
Left trimming, right trimmer and trim both sides. Simple demos in JavaScript that replace triml, trimr and trim functions. Escape is used just so you can see the spaces as %20 and makes the changes more obvious.
alert(escape(" trim left "["replace"](/^\s\s*/, "")));
alert(escape(" trim right "["replace"](/\s\s*$/, "")));
alert(escape(" trim both "[$ = "replace"](/^\s\s*/, "")[$](/\s\s*$/, "")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment