-
Notifications
You must be signed in to change notification settings - Fork 198
Python identifiers
Alex Willmer edited this page Jan 27, 2025
·
2 revisions
ASCII only, usually held in byte string type.
re.compile(r'[A-Za-z_][A-Za-z0-9_]*')
Unicode, with NFKC, held in textual string type.
str.isidentifier()
id_start = r'\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nl}\u1885\u1886\u2118\u212e\u309b-\u309c_'
id_continue = id_start + r'\p{Mc}\p{Mn}\p{Nd}\p{Pc}\u00b7\u0387\u1369-\u1371\u19da\u200c\u200d\u30fb\uff65'
regex.compile(f'[{id_start}][{id_continue}]*', regex.UNICODE)