JSFiddle - React, Tailwind, and code Playground

JavaScript

var urls = [
    'http://stackoverflow.com',
    'http://stackoverflow.com?foo=bar',
    'http://stackoverflow.com/',
    'http://stackoverflow.com/?foo=bar',
    'http://stackoverflow.com/qux',
    'http://stackoverflow.com/qux?foo=bar', 
    'http://stackoverflow.com/qux/',
    'http://stackoverflow.com/qux/?foo=bar', 
];
    
for(var i=0; i<urls.length; i++) {
    $('body').append(urls[i].replace(/\/?(\?|#|$)/, '/$1') + '<br />');
}