Skip to content

Instantly share code, notes, and snippets.

@refo
Created June 5, 2015 13:27
Show Gist options
  • Select an option

  • Save refo/47632c8a547f2d9b6517 to your computer and use it in GitHub Desktop.

Select an option

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

getbyid commented May 29, 2019

Copy link
Copy Markdown

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

@damiencorpataux

Copy link
Copy Markdown

Good !

@simcha90

Copy link
Copy Markdown

👍

@Morsmalleo

Copy link
Copy Markdown

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

@shanieMoonlight

Copy link
Copy Markdown

👍

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