简体   繁体   中英

Regular expression for website url

A URL should start with http:// or www.

http://google.com

or

www.google.com

My Regular expression is:

 [RegularExpression(@"^http(s?)\:\/\/[0-9a-zA-Z]([.\w][0-9a-zA-Z])(:(0-9))(\/?)([a-zA-Z0-9\\.\?\,\'\/\\\+&%\$#_])?$", ErrorMessage = "*")]

My code is working fine for http://google.com but not for www.google.com .

Does anyone have any suggestions?

尝试以下规则:

'#((https?://|www\.)([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM