Jul-11-2018, 12:40 PM
You should post what you tried(like in working code),and also test example with input and wanted output
I can me a mess of text that you work with,or it can be more structured.
I can me a mess of text that you work with,or it can be more structured.
(Jul-11-2018, 11:29 AM)metalray Wrote: For the second pattern, I need to make sure that the year stands alone and has no more digits before or after.
>>> import re >>> >>> s = '1980 100 18000 2000 112 2018' >>> re.findall(r'(?<!\d)\d{4}(?!\d)', s) ['1980', '2000', '2018'] # only 2 >>> s = '19 100 18000 20 1234 1 55' >>> re.findall(r'(?<!\d)\d{2}(?!\d)', s) ['19', '20', '55']