Skip to content

Instantly share code, notes, and snippets.

@tao12345666333
Created July 23, 2014 15:03
Show Gist options
  • Save tao12345666333/13edb463b04da758dade to your computer and use it in GitHub Desktop.
Save tao12345666333/13edb463b04da758dade to your computer and use it in GitHub Desktop.
正则表达式匹配中文
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
@tao12345666333
Copy link
Author

第5行,unicode(nickname,'utf8') 是为了避免 DecodeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment