In my Angular/typescript project, I am working on building a regex for a cluster endpoint that includes an IP address or hostname (FQDN) in a URL format. For instance:
Example 1 - 10.210.163.246/k8s/clusters/c-m-vftt4j5q
Example 2 - fg380g9-32-vip3-ocs.sample.company.com/k8s/clusters/c-m-8vcjbtwh
(Please note there should not be a slash at the end)
I have combined two different regular expressions: one for IP/FQDN and another for matching the remaining part of the URL like "/k8s/clusters/c-m-vftt4j5q". Here are the regex patterns:
First regex pattern for IP/FQDN: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$
Second regex pattern for the rest of the URL: ^\/(([a-zA-Z0-9-]+)\/)+([a-zA-Z0-9-]+)$
Combined regex pattern:
^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9]))[\/]{1}(([a-zA-Z0-9-]+)\/)+([a-zA-Z0-9-]+)$
However, this combined regex matches with Example 2 but not Example 1. What modifications should I make to correct this?