Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload