Actually, not understanding the script probably cost a bit of time.
That regex is a very lame attempt to strip a path from a filename, leaving just the name part (the basename). However, it assumes firstly that if you have a backslash to start, every other delimiter would be a backslash, or conversely on forward slashes. Seeing Windoze allows both (mixed), that's a clue.
Apart from that, there's an error: if you match in the second part of the regex (after the `or' | ), the replacement should be \2, since \1 is not defined then (first part not matched). So if you match on the second part you get an empty string.
So, the thing to do is to match on the first part: give it any character(s) (the .+) then a backslash, then something other than a backslash, which will be replaced by the "something other". So "x\/a/b/c/d" -> "/a/b/c/d", and you have a root based path, which can be a bit easier to work with.
gdm@shrdlu.kw.net