简体   繁体   English

正则表达式一个或多个组-正则表达式以匹配带有和不带有端口号的URL

[英]Regular expression one or more groups - regex to match a url with and without port number

I have a regular expression to match a URL 我有一个正则表达式来匹配URL

(^http.?://\b)(.*):(\d*)(.*)

http://udara.com:8907/phpmyadmin/index.php

matches the above expression. 与上面的表达式匹配。 However, there may be cases where port is not specified in the URL as below: 但是,可能在以下情况下未在URL中指定端口:

http://udara.com/phpmyadmin/index.php?token=48bdb70fd4f1e6abe5ecb84192c1835e

In this case the expression does not match. 在这种情况下,表达式不匹配。

How to say zero or more of the 3rd group. 怎么说第三组的零个或多个。 Note that there may be IPs instead of the domain udara.com 请注意,可能有IP而不是域udara.com

Try the following: (^http.?://([a-zA-Z\\-]+)(?::(\\d*))?(.*) 请尝试以下操作: (^http.?://([a-zA-Z\\-]+)(?::(\\d*))?(.*)

EIDT: EIDT:

^http.?://([a-zA-Z\\-\\.]+)(?::(\\\\d*))?(.*) - java ^http.?://([a-zA-Z\\-\\.]+)(?::(\\\\d*))?(.*) -Java

^http.?:\\/\\/([a-zA-Z\\-\\.]+)(?::(\\d*))?(.*) - perl (and regex101.com) ^http.?:\\/\\/([a-zA-Z\\-\\.]+)(?::(\\d*))?(.*) -Perl(和regex101.com)

这可能会有所帮助:

http://[az\\.]+(:[0-9]+)*/.+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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