How can I parse various URL structures that may include:
protocol://category
protocol://category/:id
protocol://category/:id#hash
For example:
protocol://feed > feed
protocol://blog/123 > feed, 123
protocol://video/123#ABC > feed, 123, ABC
The protocol://
segment is constant, while the other parts are dynamic. I am seeking a way to extract these elements into an array containing:
[1] category
[2] id (if available)
[3] hash (if available)
I currently have a regex pattern of
(?:protocol:\/\/)(\w+)(?:\/?(\w*)(?:(?:$|#)?(.+$))?)?
which appears to be functional, but I am open to suggestions for improvement.
I have been testing this in regex101