[python] [:lower:] apod.?

propanbutan propanbutan na gmx.net
Pátek Březen 31 13:27:52 CEST 2017


"Alexandr Rosen" <alexandr.rosen na ff.cuni.cz> wrote:
> Diky moc, ale jak se s tim pracuje? Daji se ty znakove konstanty
> pouzit v regularnich vyrazech? Jak?

import string
re_upper = ur'[%s]+' % string.uppercase
re_lower = ur'[%s]+' % string.lowercase

ale

>>> import string, locale
>>> locale.setlocale(locale.LC_CTYPE, 'cs_CZ')
'cs_CZ'
>>> string.lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> locale.setlocale(locale.LC_CTYPE, 'de_DE')
'de_DE'
>>> string.lowercase
'abcdefghijklmnopqrstuvwxyz\xb5\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8
\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb
\xfc\xfd\xfe\xff'

python 2.5.1 ymmv
jde to nahradit dalsi prasarnou

import sys
uppercase = u''.join(unichr(i) for i in range(sys.maxunicode)
  if unichr(i).isupper())
lowercase = u''.join(unichr(i) for i in range(sys.maxunicode)
  if unichr(i).islower() )


Další informace o konferenci Python