Python string have not control characters
<p>i have proxy string:</p>

<pre><code>proxy = '127.0.0.1:8080'
</code></pre>

<p>i need check is it real string:</p>

<pre><code>def is_proxy(proxy):
    return not any(c.isalpha() for c in proxy)
</code></pre>

<p>to skip string like:</p>

<pre><code>fail_proxy = 'This is proxy: 127.0.0.1:8080'
</code></pre>

<p>but some time i have like:</p>

<pre><code>fail_proxy2 = '127.0.0.1:8080\r'
is_proxy(fail_proxy2) is True
True
</code></pre>

<p>need False</p>

<p>Try the following specific approach using <code>re</code> module(regexp):</p>

<pre><code>import re

def is_proxy(proxy):
    return re.fullmatch('^\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}:\d{1,5}$', proxy) is not None

proxy1 = '127.0.0.1:8080'
proxy2 = '127.0.0.1:8080\r'

print(is_proxy(proxy1))   # True
print(is_proxy(proxy2))   # False
</code></pre>

<p>As for port number (<code>\d{1,5}</code>): range <strong>1-65535</strong> are available for port numbers</p>

python string control-characters