0

I am not able to understand why I am getting the output like this for the second print statement. Could u pls help me out

import re print(re.sub(r'AB?', '*', 'ABBBCD')) # OUTPUT - *BBCD print(re.sub(r'AB??', '*', 'ABBBCD')) # OUTPUT - *BBBCD

29th Jul 2022, 3:59 PM
Levi
Levi - avatar
3 Answers
0
Which Output do you expect then or what should come out?
29th Jul 2022, 5:32 PM
Felix Alcor
Felix Alcor - avatar
0
Felix Alcor I am asking for the reason or explanation as to why I am getting that output.
29th Jul 2022, 5:43 PM
Levi
Levi - avatar
0
Seems like Double '??' only take the first char and not the second. Here some Testing I have done. https://code.sololearn.com/c7pDd7kOM2I1/?ref=app
29th Jul 2022, 6:04 PM
Felix Alcor
Felix Alcor - avatar