Ask for help on using re

Jach Feng jfong at ms4.hinet.net
Thu Aug 5 05:40:30 EDT 2021


I want to distinguish between numbers with/without a dot attached:

>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
>>> re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 ']

I can guess why the 'ch 23' appears in the second list. But how to get rid of it?

--Jach


More information about the Python-list mailing list