JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

<div id="result"></div>

CSS

#result {font-family: "Courier New";}

JavaScript

var testURLs = [
    "http://localhost:8080/blah/blah/index.php?p=1",
    "http://localhost:8080/blah/blah/index.php",
    "http://localhost:8080/blah/blah/",
    "http://localhost:8080/blah/blah"
];

function cleanURL(url) {
    return(url.replace(/\?.*$/, "").replace(/\/[^\/]*$/, "") + "/");
}

for (var i = 0; i < testURLs.length; i++) {
    var newURL = cleanURL(testURLs[i]);
    $("#result").append(newURL + "<br>");
}