Regex/Python – why is non capturing group captured in this case?

Each element of this raw data array is parsed by regex

['rntttttt', 
 'Monday, Tuesday, Wednesday, Thursday, Friday, Saturday:', 
 ' 12:00 pm to 03:30 pm & 07:00 pm to 12:00 amttttt',      
 'rntttttt', 
 'Sunday:', 
 ' 12:00 pm to 03:30 pm & 07:00 pm to 12:30 amttttt']

This is my regex (r|n|t)|(?:D)(:)

https://regex101.com/r/fV7wI2/1

enter image description here

Please note that I’m trying to match the : after Saturday but not the : in Time formats eg 12:00

Although the above image classifies capturing/non capturing groups properly

on running re.sub("(r|n|t)|(?:D)(:)",'',"Monday, Tuesday, Wednesday, Thursday, Friday, Saturday:")

returns

'Monday, Tuesday, Wednesday, Thursday, Friday, Saturda' (missing ‘y’ after saturday)

instead of

'Monday, Tuesday, Wednesday, Thursday, Friday, Saturday'

why is this so?


Source: regex

Leave a Reply