On Thu, 5 Aug 2021 02:40:30 -0700 (PDT), Jach Feng <jf...@ms4.hinet.net> wrote: 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?
>>> re.findall(r'ch \d+[^.0-9]', "ch 1. is ch 23. is ch 4 is ch 56 is ") ['ch 4 ', 'ch 56 '] -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list