我有一個用例,可以發生任何相對格式。喜歡:
const URL1 = "./hello-world"
const URL2 = "../hello-world"
const URL3 = "../../hello-world"
const URL4 = "../../../hello-world"
const URL5 = "../../../../hello-world"
等等等等。我關心的是實際的絕對路徑,這意味著:
output: hello-world
我可以使用哪些正則運算式或函式(最好在 JS 中)來實作這一點?
uj5u.com熱心網友回復:
const input = "../../../../hello-world";
const output = input.replace(/\. \//g, '');
console.log(output); // hello-world
它的作用是找到“。” 以“/”結尾的鏈。它將匹配以斜線結尾的每一個點鏈。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/520170.html
