How to check a text contains \
<pre><code>def check(text):
    pattern = re.compile(r'\\')
    rv = re.match(pattern, text)
    if rv:
        return True
    else:
        return False

print check('\mi') # True
print check('\ni') # False
</code></pre>

<p>Actually,I want text contains '\' is illegal.</p>

<p>But '\n', '\b',etc, python treats them specially,so I can not match them out.</p>

<p>Any solutions?</p>

<p>Why would you need or want to use a regex for this?</p>

<pre><code> return '\\' in text
</code></pre>

python