我遇到了一点正则表达式问题。
我正在尝试获取此网址 videoplay
中的路径。
http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#hello
如果我使用这个正则表达式 /.+
它也匹配 /video
。
我需要某种反/否定匹配来不包括 //
最佳答案
如果您的 JavaScript 网络应用需要此功能:我在此主题上找到的最佳答案是 here .代码的基本(也是原始)版本如下所示:
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
谢谢约翰·朗,你造就了白昼!
关于javascript - 来自 URL 的正则表达式 URL 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12023430/