Python Regex remove numbers and numbers with punctaution
<p>I have the following string</p>

<pre><code> line = "1234567 7852853427.111 https://en.wikipedia.org/wiki/Dictionary_(disambiguation)"
</code></pre>

<p>I would like to remove the numbers 1234567 7852853427.111 using regular expresisions</p>

<p>I have this re
    nline = re.sub("^\d+\s|\s\d+\s|\s\d\w\d|\s\d+$", " ", line)</p>

<p>but it is not doing what i hoped it would be doing.</p>

<p>Can anyone point me in the right direction?</p>

<p>I think this is what you want:</p>

<pre><code>nline = re.sub("\d+\s\d+\.\d+", "", line)
</code></pre>

<p>It removes the numbers from line. If you want to keep the space in front of "http..." your second parameter should of course be " ".</p>

<p>If you also want to record the individual number strings you could put them in groups like this:</p>

<pre><code>&gt;&gt;&gt; result = re.search("(\d+)\s(\d+\.\d+)", line)
&gt;&gt;&gt; print(result.group(0))
1234567 7852853427.111
&gt;&gt;&gt; print(result.group(1))
1234567
&gt;&gt;&gt; print(result.group(2))
7852853427.111
</code></pre>

<p>A great way to learn and practice regular expressions is <a href="http://regex101.com" rel="nofollow">regex101</a>.</p>

python regex