XSD - URL 的正则表达式/模式
我不太擅长常规表达,需要一种模式来仅允许以 HTTP://www
开头的 URL。
我找到了很多 URL 示例,但它们似乎都过于复杂,我确信它应该非常简单。有人可以帮忙吗?
I am not very good with regular experessions and need a pattern to only allow URLS that begin with HTTP://www
.
I have found lots of examples for URLS but they all seem over compliated and I'm sure it should be very simple. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTTP://www
- 他们必须以此开头?好的。这就是你的正则表达式。对其进行不区分大小写的设置,一切就完成了。当您应该“接受”可以更改的字符串时,正则表达式的事情就会变得有趣。您需要允许“https”吗?网址中域名之前是否有授权部分? (如果您这样做了,您就会知道)这就是正则表达式变得复杂的时候。
编辑
可能有更好的方法,但我有一段时间没有在 XSD 中这样做了。这将匹配
HTTP://www
- they must start with that? ok. that's your regular expression. throw case insensitive on it and you're all set.Things get interesting with regular expressions when you should 'accept' a string that can change. do you need to allow 'https' ? will you have an authorization section in the url before the domain? (you would know already if you did) that's when a Regex can get complicated.
Edit
there could be a better way, but I haven't done this in an XSD in a while. This will match