I am trying to understand something I have the following instruction
re.sub(r'd?(dw+|wb)', 'z', 'ad2aba')
Since it is supposed to replace the expresion d?(dw+|wb)'
by z in ad2aba
I thought it will give adz since we try to have the longest expression by default
So i thought d? give nothing
dw+ give 2aba
And so we replace it by z and have adz but I am incorrect and the result is actually adza and not adz. The function takes d?wb instead dw+ wich gives a longer expression. I do not understand why ? Why choosing that option re.sub is supposed to be greedy and search for the longest one.
Is that the ?d that changes that ?
1