Find substring between / and \
<p>After <a href="http://stackoverflow.com/questions/39420685/get-a-list-of-subdirectories">Get a list of subdirectories</a>, I got strings of that form:</p>

<pre><code>In [30]: print(subdir)
 foousa          0 2016-09-07 19:58 /projects/foousa/obama/trump/10973689-Parthenon
drwx------   - 
</code></pre>

<p>and when I try this <a href="http://stackoverflow.com/a/3368991/2411320">answer</a>:</p>

<pre><code>In [23]: print find_between( subdir, "/", "\\" )


In [24]: print find_between( subdir, "\/", "\\" )
</code></pre>

<p>I don't get anything, maybe a newline only... What I was aiming for is <code>10973689-Parthenon</code>.</p>

<p>What am I missing?</p>

<p>I am using <a href="/questions/tagged/spark" class="post-tag" title="show questions tagged &#39;spark&#39;" rel="tag">spark</a>, but I couldn't see how this would matter...</p>

<p><strong>Using <code>re</code></strong>:</p>

<pre><code>import re

subdir = ' foousa          0 2016-09-07 19:58 /projects/foousa/obama/trump/10973689-Parthenon\ndrwx------   - '
match = re.search(r'/([^/\n]+)\n', subdir)
print(match.group(1))
</code></pre>

<p><strong>Using indexes:</strong></p>

<pre><code>subdir = ' foousa          0 2016-09-07 19:58 /projects/foousa/obama/trump/10973689-Parthenon\ndrwx------   - '
begin = subdir.rindex('/') + 1
end = subdir.rindex('\n')
result = subdir[begin:end]
print(result)
</code></pre>

<p>output:</p>

<pre><code>10973689-Parthenon
</code></pre>

python linux string apache-spark substring