Javascript and Regex: Removing Trailing # and / From the URL

Need to remove the trailing # or / or both from the end of a URL? Try using the following Regex:

var url = location.href.replace(/(\/#|\/|#)$/, '');

Note that it’s best to leave a trailing slash in your URLs but in this case, I was comparing the location.href to a list of URLs from a database and I wanted the comparison to be consistent.