Use regex to match 5 num, dot, 1 num, dot, 5 num
<p>I'm trying to create regex to match the following pattern:</p>

<pre><code>00000.1.17372
</code></pre>

<p>i.e: <code>5 Numbers DOT 1 Number DOT 5 Numbers</code></p>

<p>I have tried the following re.match:</p>

<pre><code>find = re.match('d{5}.d{1}.d{5}', string)
</code></pre>

<p>In context:</p>

<pre><code>import re

string = "{u'blabla': u'asdf', u'dd': u'a', u'cotry': u'jjK', u'l': u'/q/iii:00000.1.17372', u'stfe': u'', u'fdfhdiufhi': u'GB', u'y_name': u'Unitm', u'mw': u'00000.1.17372'}"

find = re.match('d{5}.d{1}.d{5}', string)

print find
</code></pre>

<p>However, this doesn't seem to work, as the output is:</p>

<pre><code>None
</code></pre>

<p>Use the following with <code>re.findall</code>:</p>

<pre><code>r'\b\d{5}\.\d\.\d{5}\b'
</code></pre>

<p>See the <a href="https://regex101.com/r/ExVBOp/1" rel="nofollow">regex demo</a></p>

<p>The point is:</p>

<ul>
<li>to match a digit, you need to use <code>\d</code></li>
<li>a dot must be escaped to match a literal dot</li>
<li>to match whole words, you need to use <code>\b</code> word boundary or you will find matches of 5-digit chunks in <code>2234567654</code> like strings</li>
<li><code>re.findall</code> will return a list of all non-overlapping matches (since there are no capturing groups in this pattern) </li>
</ul>

<p>Sample Python code:</p>

<pre><code>import re
regex = r"\b\d{5}\.\d\.\d{5}\b"
test_str = "{u'blabla': u'asdf', u'dd': u'a', u'cotry': u'jjK', u'l': u'/q/iii:00000.1.17372', u'stfe': u'', u'fdfhdiufhi': u'GB', u'y_name': u'Unitm', u'mw': u'00000.1.17372'}"
matches = re.findall(regex, test_str)
print(matches)
</code></pre>

python regex python-2.7