Letter class in re
Tim Chase
python.list at tim.thechases.com
Mon Mar 9 08:50:17 EDT 2015
On 2015-03-09 13:26, Antoon Pardon wrote:
> Op 09-03-15 om 12:17 schreef Tim Chase:
>> (?:(?!_|\d)\w)
>
> So if I understand correctly the following should be a regular
> expression for a python3 identifier.
>
> (?:(?!_|\d)\w)\w+
If you don't have to treat it as an atom, you can simplify that to
just
(?!_|\d)\w+
which just means that the first character can't be an underscore or
digit.
Though for a Py3 identifier, the underscore is acceptable as a first
character ("__init__"), so you can simplify it even further to just
(?!\d)\w+
-tkc
More information about the Python-list
mailing list