Regex pattern within text
<p>I have a long string of data which looks like:</p>

<pre><code>dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd
</code></pre>

<p>Notice that the '12345.123' pattern is the same. I want to split the string on it using python (so <code>s.split(&lt;regex&gt;)</code>).</p>

<p>What would be the appropriate regex?</p>

<pre><code>'[0-9]{5}.[0-9]{3}'
</code></pre>

<p>does not work; I presume it expects whitespace around it(?).</p>

<p>Your regex should be <code>'\d{5}\.\d{3}'</code>. </p>

<p>Check the usage of <code>.</code> instead of <code>\.</code>. That is because, '.' (Dot.) in the default mode, matches any character except a newline. Refer <a href="https://docs.python.org/2/library/re.html" rel="nofollow">regex</a> document. Whereas <code>\s</code> means <code>dot</code> in your string.</p>

<p>For example:</p>

<pre><code>import re
my_string = 'dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd'
my_regex = '\d{5}\.\d{3}'
re.split(my_regex, my_string)
# returns: ['dstgfsda', 'gsrsvrvsdfcsd', 'tsrsd']
</code></pre>

<p><strong>Explanation</strong> on how <code>'\d{5}\.\d{3}'</code> works:</p>

<p><code>\d</code> means any digit between <code>0-9</code>. <code>\d{5}</code> sub-string with any 5 consecutive digits. <code>\.</code> means digits followed by single <code>.</code>. At last <code>\d{3}</code> means any 3 digits after <code>.</code> </p>

python regex