并匹配包含'#'或'的网址? '直到那两个人之前的角色。 这条路 http://example.com/index.php?p=Hey - > http://example.com/index.php
到目前为止,我只选择某些文件类型或文件夹(除了一种情况)时,我所使用的正则表达式代码效果很好:
感谢任何帮助。谢谢大家。
这是正则表达式:
^(?<protocol>http(s?))://(?<domain>[^/\r\n#?]+)(?<path>/[^?#]*(?:html|php|/))?
答案 0 :(得分:1)
不确定您使用的语言是什么,但如果您已经有了一个URL列表,则可能不需要使用正则表达式。
在C#中,您可以这样做:
string a = "http://example.com/index.php?p=Hey";
string b = a.Remove(a.IndexOfAny(new char[] {'?', '#'}, 0));
答案 1 :(得分:1)
这可能会做你想要的:
^(?<protocol>http(s?))://(?<domain>[^/\s#?]+)(?<path>/[^\s#?]*)?(?<query>.*)?
查询将包含您可能想要忽略的其余部分。