Created
July 23, 2014 15:03
-
-
Save tao12345666333/13edb463b04da758dade to your computer and use it in GitHub Desktop.
正则表达式匹配中文
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
nickname = raw_input('Please input your nickname > ') | |
if not re.search(u'^[\u4e00-\u9fa5a-zA-Z0-9]+$', unicode(nickname,'utf8')): | |
print 'Your nickname format is error, please try again !' | |
else: | |
print 'Hello %s'% nickname | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第5行,unicode(nickname,'utf8') 是为了避免 DecodeError