Match a substring in Pandas wit str.extract method
<p>I have a string looking like:</p>

<pre><code>29818-218705-61709-2    
</code></pre>

<p>I want to extract the second to last 5 digits number between the two dashes</p>

<pre><code>61709
</code></pre>

<p>each string is contained in a pandas series:</p>

<p>I came up with:</p>

<pre><code>df.id.str.extract(r'[.-]([0-9]{5})[.-]?')
</code></pre>

<p>but it extracts the first 5 digits group.</p>

<p>I can I match the one I want?</p>

<p>You can try:</p>

<pre><code>&gt;&gt;&gt; s = "29818-218705-61709-2 "
&gt;&gt;&gt; s.split("-")[2]
'61709'
</code></pre>

python regex string pandas