It depends on the context you are. You shouldn't be needing to parse any URL... ever.
0. Do you need that information at a server or client side?
1. Are you in a plugin module, override or a layer?
2. If in a module, which type?
3. In what part/method/function do you need that ID?
4. If you are not in a plugin context, then exactly what line of the core are you editing? (link to the github repo)