Skip to content

Instantly share code, notes, and snippets.

@refo
Created June 5, 2015 13:27
Show Gist options
  • Save refo/47632c8a547f2d9b6517 to your computer and use it in GitHub Desktop.
Save refo/47632c8a547f2d9b6517 to your computer and use it in GitHub Desktop.
javascript - Remove leading slashes
'/example/string/'.replace(/^\/+/g, '');
// Should remove all leading slashes and return 'example/string/'
@getbyid
Copy link

getbyid commented May 29, 2019

Thanks! Without g also works:
'///example/string/'.replace(/^\/+/, '');

@damiencorpataux
Copy link

Good !

@simcha90
Copy link

👍

@Morsmalleo
Copy link

Beautiful, absolutely brilliant! Needed something like this in a node project I'm maintaining, thank you heaps ❤️

@shanieMoonlight
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment