Regex: Exclude a mix of fixed and unknown length pattern
<p>I have a string like this:</p>

<pre><code>'Global Software Version (DID 0xFD15): 4.5.3'
</code></pre>

<p>And I want to find:</p>

<pre><code>4.5.3
</code></pre>

<p>The string does always start with <code>Global Software Version</code>, but <code>(DID 0xFD15)</code> is a variable part, it is different each time.</p>

<p><strong>What I did:</strong></p>

<pre><code>&gt;&gt;&gt; x = 'Global Software Version (DID 0xFD15): 4.5.3'
&gt;&gt;&gt; re.search('(?&lt;=Global Software Version ).*', x).group().split(':')[1].strip()
'4.5.3'
</code></pre>

<p>Anybody with a better idea? Only with regex? </p>

<p>So you can do multiple things here. The easiest solution would be:</p>

<pre><code>&gt;&gt;&gt; x = 'Global Software Version (DID 0xFD15): 4.5.3'
&gt;&gt;&gt; version = re.search('\d+[.]\d+[.]\d+', s).group()
&gt;&gt;&gt; version
'4.5.3'
</code></pre>

<p>But this would also work:</p>

<pre><code>&gt;&gt;&gt; version = 'Global Software Version (DID 0xFD15): 4.5.3'.split(":")[1].strip()
&gt;&gt;&gt; version
'4.5.3'
</code></pre>

<p>Hope this helps!</p>

python regex