If the number of paths is arbitrary, then you need a two-step approach:
First, remove all the "uninteresting stuff" from the string.
Search for .*?/\d+/([^/]+/?)
and replace all with $1
.
In C#: resultString = Regex.Replace(subjectString, @".*?/\d+/([^/]+/?)", "$1");
In JavaScript: result = subject.replace(/.*?\/\d+\/([^\/]+\/?)/g, "$1");
This will transform your string into VOBSWeb/VobsWebUI/VaultWeb/func.js
.
Second, copy the filename to the front of the string.
Search for (.*/)([^/]+)$
and replace with $2;$1$2
.
C#: resultString = Regex.Replace(subjectString, "(.*/)([^/]+)$", "$2;$1$2");
JavaScript: result = subject.replace(/(.*\/)([^\/]+)$/g, "$2;$1$2");
This will transform the result of the previous operation into func.js;VOBSWeb/VobsWebUI/VaultWeb/func.js
If the number of paths is constant, then you can do it in a single regex:
Search for ^.*?/\d+/([^/]+/).*?/\d+/([^/]+/).*?/\d+/([^/]+/).*?/\d+/([^/]+)
and replace with $4;$1$2$3$4
.
C#: resultString = Regex.Replace(subjectString, @"^.*?/\d+/([^/]+/).*?/\d+/([^/]+/).*?/\d+/([^/]+/).*?/\d+/([^/]+)", "$4;$1$2$3$4");
JavaScript: result = subject.replace(/^.*?\/\d+\/([^\/]+\/).*?\/\d+\/([^\/]+\/).*?\/\d+\/([^\/]+\/).*?\/\d+\/([^\/]+)/g, "$4;$1$2$3$4");
This regex will be inefficient if the string fails to match; this could be improved with atomic grouping, but JavaScript doesn't support that.