例子:
http://example.com ---> http://example.com
ftp://username:[email protected] ---> ftp://username:[email protected]
http://example.com/path/to/somehwere ---> http://example.com
http://example.co.uk ---> http://example.co.uk
example.co.uk ---> example.co.uk
example.co.uk?user=John&pass=1234 ---> example.com.uk
我尝试了这个:
.*?(:\/{2})?.*?(?=\/|$|\?)
它适用于没有协议的网址,但其原因(?=\/|$|\?)
在于http:
你能帮我修复我的正则表达式吗?还是建议更好?
我相信这个基于前瞻性的正则表达式应该适合您:
^.+?[^\/:](?=[?\/]|$)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句