有效网站链接的正则表达式 [英] Regex expression for valid website link
本文介绍了有效网站链接的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 asp.net 应用程序中,我需要验证有效网站链接的文本.我想为此使用正则表达式验证器.任何知道如何验证网络链接用户正则表达式的人.
In my asp.net application, i need to validate the text for a valid website link. I want to use the regular expression validator for that. Anyone with any idea of how to validate the weblink user regex.
推荐答案
试试这个 -
^(?:ftp|http|https):\/\/(?:[\w\.\-\+]+:{0,1}[\w\.\-\+]*@)?(?:[a-z0-9\-\.]+)(?::[0-9]+)?(?:\/|\/(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+)|\?(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+))?$
解释下面的每个步骤 -
Explained each step below -
^ # Start at the beginning of the text
(?:ftp|http|https):\/\/ # Look for ftp, http, or https
(?: # Username:password combinations (optional)
[\w\.\-\+]+ # A username
:{0,1} # an optional colon to separate the username and password
[\w\.\-\+]*@ # A password
)?
(?:[a-z0-9\-\.]+) # The domain limiting it to just allowed characters
(?::[0-9]+)? # Server port number
(?: # The path (optional)
\/| # a forward slash
\/(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+)| # or a forward slash followed by a full path
\?(?:[\w#!:\.\?\+=&%@!\-\/\(\)]+) # or a question mark followed by key value pairs
)?$
这篇关于有效网站链接的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文