在 NodeJS 环境中,如何提取相对路径,同时不考虑数字路径参数和所有查询参数?
假设你有一个字符串形式的 url:https://localhost:8000/api/users/available/23342?name=john
目标是api/users/available从中获得。下面是一个实现,但是,它非常低效,必须有一个更好的解决方案,通过正则表达式完成这一切......
const url = 'https://localhost:8000/api/users/available/23342?name=john';
url
.split("/")
.splice("3")
.join("/")
.split("?")[0]
.replace(/\/(\d*)$/, "");
};
慕森卡
相关分类