Reputation: 41595
I want to get the anchor in a URL, where the anchor (#text) can be in these formats:
https://example.com/#section3?a=1a&b=2b
https://example.com/#section3&a=1a&b=2b
https://example.com/?a=1a&b=2b#section3
https://example.com/&a=1a&b=2b#section3
So I would have to get the following in all cases:
#section3
Anchors in the URL can only contain ASCII characters, so I though this could be used for that.
I got this, and although it seems to work, it seems to be it can be done better and shorter?
#(.)*\?|#(.)*?\&|#(.)*
Upvotes: 0
Views: 54
Reputation: 38502
If I don't misunderstood your question then this is one of many solution.
#([^?&\s]+)
Demo: https://regex101.com/r/asDvr6/1
Upvotes: 5