 <p>I know you specifically asked for regex, but you don't really need regex for this. You simply need to split the string by delimiters (in this case a backslash), then choose the part you need (in this case, the 3rd field - the first field is empty).</p> <ul> <li><p><code>cut</code> example:</p> <pre><code>cut -d '/' -f 3 &lt;&lt;&lt; "$string" </code></pre></li> <li><p><code>awk</code> example:</p> <pre><code>awk -F '/' {print $3} &lt;&lt;&lt; "$string" </code></pre></li> <li><p><code>perl</code> expression, using <code>split</code> function:</p> <pre><code>(split '/', $string)[2] </code></pre></li> </ul> <p>etc.</p>