I would not use a regex, but simply:
var url = "http://www.abc.com/h/x/y";
var ix1 = url.LastIndexOf('/');
var ix2 = url.LastIndexOf('/', ix1 - 1);
var part = url.Substring(ix2 + 1);
This is understandable without explaining the complex regex :)
(+ checking if a valid URL can be executed separately before the actual parsing)
source
share