I have the following Java String which I need to compare with the regex but these string can consist of the optional values which may be present or not present I need to perform different things based on their availability:
String 1: With serial
uri = https://myid.com/123/1234567890128/456/1111
String 2: Without Serial
uri = https://myid.com/123/1234567890128
As we can see the incoming string can have the /456/1111
or it may not have. How can I write a single regex function which checks whether it is present or not? I have written a regex but it would work only if the /456/1111
is present:
uri.matches("(http|https)://.*/123/[0-9]{13}.*)")
I tried adding the optional values after looking at some of the answers here something like this:
uri.matches("(http|https)://.*/123/[0-9]{13}+([/456/[0-9]{1,20}]?)")
But for some reason, it does not work. Can someone please help me how can I verify whether there are any strings present in uri /456/1111
or not. I feel like I am missing some small thing.