我有一个用例,任何相对格式都可以发生。类似:
const URL1 = "./hello-world"
const URL2 = "../hello-world"
const URL3 = "../../hello-world"
const URL4 = "../../../hello-world"
const URL5 = "../../../../hello-world"
等等。我所关心的是实际的绝对路径,这意味着:
output: hello-world
我可以使用哪些Regex或函数(最好是JS(来实现这一点?
const input = "../../../../hello-world";
const output = input.replace(/.+//g, '');
console.log(output); // hello-world
它的作用是找到"。"以"/"结尾的链。它将匹配以斜线结尾的每一个点链。