-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
re.I does not work as expected #70542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. ======================================================================== >>> a
'ype="str">false</latency_statistics_enabled><name type="str">Default</name><aggregates type="list"><item type="dict"><aggregate type="list"><item type="dict"><type type="str">MulticastClient</item><is'
>>> b = re.sub('\<\/?item(\s+type="dict")?\>', '', a, re.I)
>>> b
'ype="str">false</latency_statistics_enabled><name type="str">Default</name><aggregates type="list"><aggregate type="list"><type type="str">MulticastClient</item><is'
>>> b = re.sub('\<\/?item(\s+type="dict")?\>', '', a)
>>> b
'ype="str">false</latency_statistics_enabled><name type="str">Default</name><aggregates type="list"><aggregate type="list"><type type="str">MulticastClient<is' ======================================================================== |
The 4th argument of re.sub is the count, not the flags. Not a bug. |
See bpo-11957 |
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 ''. |
:-) 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. |
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. |
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. |
Thanks Matthew. :-) |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: