Any way to distinguish branch name part from file pat within a url?

Here is my case:

The input is a URL “Shows a file” (from https://github.com/gitbucket/gitbucket/wiki/List-of-URL-Formats).

Example:

https://github.com/BCN3D/BCN3D-Moveo/blob/master/STL%20files/Electronics%20box/Box.STL

I want to distinguish the actual file path part from a branch name. So, ‘master’ from ‘STL%20files/Electronics%20box/Box.STL’ in this case.

The problem is that branch name can have slashes in it. Example:

https://github.com/soswow/react-circle/blob/custom/branch/demo.gif

In this case, branch name is ‘custom/branch’ and path is demo.gif

The resulting path/branch is going to be used in an API call:

https://developer.github.com/v3/repos/contents/#get-contents

/repos/:owner/:repo/contents/:path

Where ‘:path’ just a file path only, and branch name is provided via ‘ref’ parameter.

The way we do it right now is by iteratively removing parts from everything after ‘blob/’ (in the incoming URL) waiting for non-404 response. This feels wasteful. If someone has a branch name with many slashes - we will make many useless calls.

Is there a way?

It’s been solid 3 months since I asked that. Not sure if bumping old unanswered question is ok here, but here I go