开发者

Python: Regular expression... not working?

I have this code:

    # If the username isn't alpha-numerics (inc: _, -, ., )
    if re.match('^[a-zA-Z0-9 _\-\.]+$', repName) == False:
        print 'DECLINE: '+repName
    else:
        print 'ACCEPTED: '+repName

And when i test it against this string: ɢ开发者_如何学JAVAᴀꜱᴛяɪᴄ (which is grabbed from a website) I get this returned:

ACCEPTED: ɢᴀꜱᴛÑ?ɪᴄ

Why is this getting through? Also why does Python seem to change the string?


Unsuccessful re.match is not False. It is None.

But you can also try it this way:

if re.match('^[a-zA-Z0-9 _\-\.]+$', repName):
    print 'ACCEPTED: '+repName
else:
    print 'DECLINE: '+repName
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜