我可能有这样的 URL:
- > http://193.198.112.125/foo/bar/
- > http://www.site.com/foo/bar/
- > http://193.198.112.125:4000/foo/bar/
我想做的是删除 /foo/bar/ 之前的部分,使用正则表达式,如果我有 IP/something,IP:PORT/something 或 DOMAIN/something
谢谢!
最佳答案
如果您始终使用绝对 URL(以 URL 方案开头),请尝试以下操作:
url.replace(/^[^\/]*(?:\/[^\/]*){2}/, "")
关于Javascript - 使用正则表达式删除部分 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1855408/