How to detect non-ASCII character in Python?
<p>I'm parsing multiple XML files with Python 2.7, there are some strings like: <code>string ="[2,3,13,37–41,43,44,46]"</code>. I split them to get a list of all elements, and then I have to detect elements with "–" like "37–41", but it turns out this is not a regular dash, it's a non-ASCII character:</p>

<pre><code>elements = [u'2', u'3', u'13', u'37\u201341', u'43', u'44', u'46']
</code></pre>

<p>So I need something like</p>

<pre><code>for e in elements:
  if "–" in e:
      # do something about it
</code></pre>

<p>If use that non-ASCII char in this if expression, then I get an error: <code>"SyntaxError: Non-ASCII character '\xe2' in file..."</code>.</p>

<p>I tried to replace the <code>if</code> expression with this re method:</p>

<pre><code>re.search('\xe2', e)
</code></pre>

<p>but it's not the case again. So I'm looking for a way to either convert that non-ASCII char to a regular ASCII "-" or use the ASCII number directly in the search expression.</p>