开发者

Python: Regular expression... not working?

开发者 https://www.devze.com 2023-02-06 08:32 出处:网络
I have this code: # If the username isn\'t alpha-numerics (inc: _, -, ., ) if re.match(\'^[a-zA-Z0-9 _\\-\\.]+$\', repName) == False:

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

精彩评论

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