I'm trying to figure out how to extract usernames from a URL that's captured in a form. I do have the below regex, but the issue is that the second forward slash may not exist. Here are the examples:
Sample URLs
https://test.site.com/u/username
https://test.site.com/u/username/pref/summary
I'm trying to extract the username
.
Current Regex
/u/(.*?)/
The current one I have above successfully extracts the username
, but only when there is another /
after the username. The second /
needs to be optional; it may or may not be there, and there may or may not be more after that.
I just couldn't find the correct regex to make the second /
optional (using ?
at the end didn't help) but not exactly "optional," if that makes sense.
Thanks in advance!