嘿家伙。我,想有由一个正则表达式匹配所有的URL像这样:正则表达式ISSUE - 无法匹配以无结尾的URL
- http://example.com
- http://example.com/
- http://example.com/index.html
- http://example.com/index
- http://example.com/index/
- http://www.example.com
- http://www.example.com/
- http://www.example.com/index.html
- http://www.example.com/index
- http://www.example.com/index/
,并匹配有 '#' 或'网址吗? '直到那两个人之前的角色。 这样 http://example.com/index.php?p=Hey - >http://example.com/index.php
正则表达式代码选择除了一个情况下,只有某些类型的文件或文件夹时,我至今运作良好:
- ,如果我有一个不是结束的URL无论是文件扩展名(例如:.html,.php)还是文件夹(例如:/),该模式都将无法正确匹配,因为某些URL(例如:http://example.com/about-me)将被排除。
任何帮助表示赞赏。感谢大家。
这是正则表达式:
^(?<protocol>http(s?))://(?<domain>[^/\r\n#?]+)(?<path>/[^?#]*(?:html|php|/))?
你只是想从URL中删除'?'或'#'中的所有内容吗? – morja 2011-04-27 12:05:34
基本上是的,每个网址都可以,但没有任何结局。这是因为有例如WordPress的URL: - http://myblog.com/about-me – Briganti 2011-04-27 12:08:53