用于C#中url验证的正则表达式 [英] Regex for url validation in C#

查看:97
本文介绍了用于C#中url验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要正则表达式验证输入的URL。

我的正则表达式不验证只有三个W(WWW)

它也接受www.com不正确。

请帮我解决这个问题。



我的尝试:



 ValidationExpression =^((http | ftp | https)://)?([\\\  - ] + \。)+ [\ w] +( / [\ ---/?]*)?$\"

解决方案


请查看以下内容:

[ ^ ]

可以找到你喜欢的东西

谷歌根据你想要匹配的内容提供数千个答案,没有应该匹配和不应该匹配的例子,找到适合你需要的正则表达式很复杂。

尝试:

 ^((https?:[/] [/])?(\ w + [。])+ com |((https ?:[/] [/])(+ \w)+ COM [/] | [/])\w +([/] \w +)*([/] | [[] []? ] HTML | [] PHP |。[] GIF |。] [JPG | [] PNG))

。?

I want regex which validate entered url.
My regex is not verify only three W (WWW)
It also accept www.com which is incorrect.
Please help me to fix this.

What I have tried:

ValidationExpression="^((http|ftp|https)://)?([\w-]+\.)+[\w]+(/[\w- ./?]*)?$"

解决方案

"


Look at the following:
[^]
May find something there you like


Google gives thousand of answers depending on what you want to match exactly, without example of what should match and what shouldn't, it is complicated to find the regex that fit your needs.
Try:

^((https?:[/][/])?(\w+[.])+com|((https?:[/][/])?(\w+[.])+com[/]|[.][/])?\w+([/]\w+)*([/]|[.]html|[.]php|[.]gif|[.]jpg|[.]png)?)


这篇关于用于C#中url验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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