# -*- coding: utf-8 -*-

import re

tmpString = 'Ich bin sch\xf6n!'
print tmpString
print repr(tmpString)
print str(type(tmpString)) + "\n"

try:
   tmpStringU = tmpString.decode('utf-8')
except Exception as e:
   print e

tmpStringU = tmpString.decode('unicode-escape')
print "\n" + tmpStringU
print repr(tmpStringU)
print str(type(tmpStringU)) + "\n"

dictSearch = {'strUml'    : 'schön', 
              'rawUml'    : r'schön', 
              'uniUml'    : u'schön', 
              'uniRawUml' : ur'schön',
              'strEsc'    : 'sch\xf6n', 
              'rawEsc'    : r'sch\xf6n', 
              'uniEsc'    : u'sch\xf6n',
              'uniRawEsc' : ur'sch\xf6n'}

dictStrings = { "tmpString" : tmpString, "tmpStringU" : tmpStringU }

for i in dictSearch: 
   for j in dictStrings:
      result = re.search(dictSearch[i], dictStrings[j])

      if result is None:
         result = "NICHT gefunden"
      else:
         result = result.group()
         
         if isinstance(result, str):
            result = result.decode('unicode-escape')
         

      print u'{0:10}  -  {1:10}  -  re.search: {2:20}'.format(i, j, result)
