Re: Regular expressions and Unicode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • skip@pobox.com

    #1

    Re: Regular expressions and Unicode


    JeffreyHowever, when I apply it to this Unicode string, I get only the
    Jeffreyfirst 3 letters of the surname:

    Jeffreyname = 'Anton\xc3\xadn Dvo\xc5\x99\xc3 \xa1k'

    Maybe

    name = unicode('Anton\ xc3\xadn Dvo\xc5\x99\xc3 \xa1k', "utf-8")

    ? Yup, that works:
    >>name = unicode('Anton\ xc3\xadn Dvo\xc5\x99\xc3 \xa1k', "utf-8")
    >>name
    u'Anton\xedn Dvo\u0159\xe1k'
    >>surname = r'(?u).+ (\w+)'
    >>import re
    >>surname_re = re.compile(surn ame)
    >>m = surname_re.sear ch(name)
    >>m.groups()
    (u'Dvo\u0159\xe 1k',)
Working...