常规的前pression验证URL [英] regular expression to validate the url

查看:117
本文介绍了常规的前pression验证URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我想一个普通的前pression验证URL,但我想,让这个字符(〜)的蒂尔达

Q: I want a regular expression to validate the URL but i wanna to allow this character(~)the Tilda

这样的网址:

http://stackoverflow.com/questions/~/
HTTP 或不 HTTP

在此先感谢

修改

我终于找到一个完美的一种:
<$c$c>(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])?
但我想,以允许用户与协议输入URL或没有它prevent混淆如何做到这一点。

i find a perfect one finally: (http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])? but i wanna to allow the user to enter the url with the protocol or without it to prevent any confusion how to do that.

推荐答案

要允许非连续的波浪线:

To allow non-consecutive tildes:

\w+([-+.'~]\w+)*

要允许任何地方波浪线:

To allow tildes anywhere:

[\w~]+([-+.'][\w~]+)*

这篇关于常规的前pression验证URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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