You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bpo-11957: re.sub confusion between count and flags args
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2016-02-13.00:44:14.426>created_at=<Date2016-02-13.00:19:24.626>labels= ['expert-regex', 'type-bug', 'invalid']
title='re.I does not work as expected'updated_at=<Date2016-02-15.22:11:04.050>user='https://bugs.python.org/MageshKumar'
Thanks for the inputs, It would be of great help, if someone could help me in explaining the below output :
========================================================================
>>> a
'ype="str">false</latency_statistics_enabled><name type="str">Default</name><aggregates type="list"><item type="dict"><aggregate type="list"><root><type type="str">MulticastClient</root><is'
>>> b = re.sub('\</?root\>', '', a, re.I)
>>> b
'ype="str">false</latency_statistics_enabled><name type="str">Default</name><aggregates type="list"><item type="dict"><aggregate type="list"><type type="str">MulticastClient<is'
The pattern '\</?root\>', which is the same as '</?root>', matches the string '<root>', and that is replaced with ''.
MageshKumar commented on Feb 15, 2016
MageshKumarmannequin
MannequinAuthor
More actions
:-)
Thanks a lot Matthew for the inputs.
If we compare the first example (<item>) and the <root> example, I am using re.I as the third element. But for the <root> example, still I am not to get the substitution happening correctly.
Could you pls, let me know the reason of change in behaviour.
MageshKumar commented on Feb 15, 2016
MageshKumarmannequin
MannequinAuthor
More actions
Corrected Message :
If we compare the first example (<item>) and the <root> example, I am using re.I as the third element. But for the <root> example, still I am able to get the substitution happening correctly.
Could you pls, let me know the reason of change in behaviour.
mrabarnett commented on Feb 15, 2016
mrabarnettmannequin
Mannequin
More actions
The 3rd argument is the count (the maximum number of replacements, although 0 means no limit, not no replacements). You're passing in the flag re.I instead. re.I happens to have the numeric value 2, so you're telling it to do no more than 2 replacements.
Activity
MageshKumar commentedon Feb 13, 2016
I am in the process of re.sub the tag <item type="dict"> </item> with empty string from a xml output line.
If "re.I" is used, I am not able to remove the complete tag.
========================================================================
========================================================================
mrabarnett commentedon Feb 13, 2016
The 4th argument of re.sub is the count, not the flags.
Not a bug.
ezio-melotti commentedon Feb 13, 2016
See bpo-11957
MageshKumar commentedon Feb 15, 2016
Thanks for the inputs, It would be of great help, if someone could help me in explaining the below output :
========================================================================
========================================================================
mrabarnett commentedon Feb 15, 2016
The pattern '\</?root\>', which is the same as '</?root>', matches the string '<root>', and that is replaced with ''.
MageshKumar commentedon Feb 15, 2016
:-)
Thanks a lot Matthew for the inputs.
If we compare the first example (<item>) and the <root> example, I am using re.I as the third element. But for the <root> example, still I am not to get the substitution happening correctly.
Could you pls, let me know the reason of change in behaviour.
MageshKumar commentedon Feb 15, 2016
Corrected Message :
If we compare the first example (<item>) and the <root> example, I am using re.I as the third element. But for the <root> example, still I am able to get the substitution happening correctly.
Could you pls, let me know the reason of change in behaviour.
mrabarnett commentedon Feb 15, 2016
The 3rd argument is the count (the maximum number of replacements, although 0 means no limit, not no replacements). You're passing in the flag re.I instead. re.I happens to have the numeric value 2, so you're telling it to do no more than 2 replacements.
MageshKumar commentedon Feb 15, 2016
Thanks Matthew. :-)