开发者

python regex [:alpha:]

开发者 https://www.devze.com 2023-02-06 23:05 出处:网络
I\'m using this regex in Python: import re >>> ER = re.compile(\'^\\w{0,30}$\', re.U) >>> ER.sub(\'.\', \'Maçã\')

I'm using this regex in Python:

import re

>>> ER = re.compile('^\w{0,30}$', re.U)

>>> ER.sub('.', 'Maçã')

>>>....

But a wanna catch only letters, [A-Z] does not wo开发者_如何学Gork for me, because i need letters with accent . Is there any way to use POSIX? [:alpha:], something like that or another solution?

Thanks!


Modified the regex - how about

ER = re.compile(u'^[^\W\d_]{1,30}$', re.U)
s = ER.sub(u'.', u'Maçã')

matches u'Maçã' but not u'Maçã01'.

0

精彩评论

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