title: arabic regex and MySQLdb in python
body: <p>I've tried to get certain Arabic string from web page then store these strings into db.</p>
  
  <p><strong>The first problem</strong></p>
  
  <p>The only way I could is to specify how many letters are they by using <code>.</code> and use unicode, like this:</p>
  
  <pre><code>import urllib,re
  content=urllib.urlopen("http://example.com/content.html").read()
  content = unicode(content,"utf-8")
  Strings = re.findall("&lt;Strong&gt;...........&lt;/strong&gt;",content) # it will work fine and fetch it but only strings with 11 char or letter (11 place) 
  </code></pre>
  
  <p><strong>Second problem</strong></p>
  
  <p>When I tried to write it to text file it displays:</p>
  
  <blockquote>
    <p>UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)</p>
  </blockquote>
  
  <p>And when I've tried to store it into database it displays:</p>
  
  <blockquote>
    <p>ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\xd8\xa7\xd9\x84\xd9\x82\xd8\xb5\xd9\x8a\xd8\xb1)' at line 1")</p>
  </blockquote>
  
  <p>What I've think about is to fetch it then encode it into base64 then store it into db 
  but still got an error:</p>
  
  <blockquote>
    <p>UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)</p>
  </blockquote>