开发者

homepage regexp matching

开发者 https://www.devze.com 2023-03-14 16:01 出处:网络
I\'m trying to write a regexp which allow me to filter out all the url addresses having this shape. http://foo.com/

I'm trying to write a regexp which allow me to filter out all the url addresses having this shape.

http://foo.com/
http://foo
http://foo.*

But not the following:

http://foo.com/subfoo
http://foo.com/subfoo/
http://foo.com/subfoo/subsubfoo..

In order to match the second url group i've written the following regexp:

http://.*/.
开发者_运维知识库

However my problem is search the regexp matching the first group. So i need a way to say:

if after http://.* or http.//.*/ there is nothing, matches the pattern.

I've read something on lookhaead. I don't know it this might be the right way. Any idea? Thanks for your answer.


A bit late, but this worked for me:

http://[^/]*[/]*$


/^http:\/\/[^/?#]*\/./i

should match only http URLs with a path component other than /.


Don't forget query strings like this: http://foo.com/?search

/^http:\/\/[^/?#]*\/[^?]/i 
0

精彩评论

暂无评论...
验证码 换一张
取 消