正则表达式验证网站与特定页面的索引 [英] Regex to validate the index of a website vs. a specific page

查看:27
本文介绍了正则表达式验证网站与特定页面的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个正则表达式,它可以让我验证字符串是否是对网站地址或该网站中特定页面的引用.

I'm looking for a regex that will allow me to validate whether or not a string is the reference to a website address, or a specific page in that website.

所以它会匹配:

http://google.com
ftp://google.com
http://google.com/
http://lots.of.subdomains.google.com

但不是:

http://google.com/search.whatever
ftp://google.com/search.whatever
http://lots.of.subdomains.google.com/search.whatever

有什么想法吗?我不太清楚如何处理允许 URL 末尾的 /.

Any ideas? I can't quite figure out how to handle allowing the / at the end of the URL.

推荐答案

试试这个:

(http|ftp|https)://([a-zA-Z0-9\-\.]+)/?

这篇关于正则表达式验证网站与特定页面的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆