每天CookBook之Python-030

  • 在unicode中使用正则表达式
import re

num = re.compile('\d+')
print(num.match('123'))
print(num.match('\u0661\u0662\u0663'))

arabic = re.compile('[\u0600-\u06ff\u0750-\u077f\u08a0-\u08ff]+')
pat = re.compile('stra\u00dfe', re.IGNORECASE)
s = 'straße'

print(pat.match(s))
print(pat.match(s.upper))
print(s.upper())
<_sre.SRE_Match object; span=(0, 3), match='123'>
<_sre.SRE_Match object; span=(0, 3), match='١٢٣'>
<_sre.SRE_Match object; span=(0, 6), match='straße'>
None
STRASSE
posted @ 2016-07-14 21:07  4Thing  阅读(115)  评论(0编辑  收藏  举报