Split and check first 8 digits are met
<p>I have some data that looks like this, when reading this data from a file, is there a way to only add to the list if the first 8 digits are met?</p>

<pre><code>11111111 ABC Data1
</code></pre>

<p>my current method is only splitting the space in between</p>

<pre><code>Number = descr.split(' ')[0]
</code></pre>

<p>If you want to only add a 8 digit number from an input string, do it as shown below</p>

<pre><code>descr = input()
reqd_int = int( descr.split(' ')[0:8] )
</code></pre>

<p>This will fail if the input contains less than 8 integers at the start.</p>

<p>The other option is to use regular expressions, use it as shown below</p>

<pre><code>import re
reqd_int = int(re.search('\d{8}', descr))
</code></pre>

<p>What the re.search() function does is,for the first paramete, <code>\d</code> stands for single integers and the <code>{8}</code> tells it to look 8 such contagious block of integers.</p>

<p>You can look up more on regular expressions <a href="https://duckduckgo.com/?q=regex+cheat+sheet&amp;ia=cheatsheet" rel="nofollow">here</a>.</p>

python python-3.x