Reputation: 6453
I have a regular expression to match a 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:
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
Upvotes: 0
Views: 75
Reputation: 115388
Try the following: (^http.?://([a-zA-Z\-]+)(?::(\d*))?(.*)
EIDT:
^http.?://([a-zA-Z\-\.]+)(?::(\\d*))?(.*)
- java
^http.?:\/\/([a-zA-Z\-\.]+)(?::(\d*))?(.*)
- perl (and regex101.com)
Upvotes: 1