常规的前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
在此先感谢
修改
我终于找到一个完美的一种:
(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?$c$c>
但我想,以允许用户与协议输入URL或没有它prevent混淆如何做到这一点。
i find a perfect one finally:
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
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~]+)*