Issue 26354: re.I does not work as expected (original) (raw)

Created on 2016-02-13 00:19 by Magesh Kumar, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (9)
msg260216 - (view) Author: Magesh Kumar (Magesh Kumar) Date: 2016-02-13 00:19
I am in the process of re.sub the tag 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>DefaultMulticastClient<is' >>> b = re.sub('\<\/?item(\s+type="dict")?\>', '', a, re.I) >>> b 'ype="str">false</latency_statistics_enabled>DefaultMulticastClient<is' >>> b = re.sub('\<\/?item(\s+type="dict")?\>', '', a) >>> b 'ype="str">false</latency_statistics_enabled>DefaultMulticastClient<is' ========================================================================
msg260219 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2016-02-13 00:43
The 4th argument of re.sub is the count, not the flags. Not a bug.
msg260220 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2016-02-13 00:44
See #11957
msg260328 - (view) Author: Magesh Kumar (Magesh Kumar) Date: 2016-02-15 19:14
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>DefaultMulticastClient<is' >>> b = re.sub('\</?root\>', '', a, re.I) >>> b 'ype="str">false</latency_statistics_enabled>DefaultMulticastClient<is' ========================================================================
msg260329 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2016-02-15 19:28
The pattern '\</?root\>', which is the same as '</?root>', matches the string '', and that is replaced with ''.
msg260330 - (view) Author: Magesh Kumar (Magesh Kumar) Date: 2016-02-15 19:39
:-) Thanks a lot Matthew for the inputs. If we compare the first example () and the example, I am using re.I as the third element. But for the example, still I am not to get the substitution happening correctly. Could you pls, let me know the reason of change in behaviour.
msg260331 - (view) Author: Magesh Kumar (Magesh Kumar) Date: 2016-02-15 19:40
Corrected Message : If we compare the first example () and the example, I am using re.I as the third element. But for the example, still I am able to get the substitution happening correctly. Could you pls, let me know the reason of change in behaviour.
msg260334 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2016-02-15 21:13
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.
msg260335 - (view) Author: Magesh Kumar (Magesh Kumar) Date: 2016-02-15 22:11
Thanks Matthew. :-)
History
Date User Action Args
2022-04-11 14:58:27 admin set github: 70542
2016-02-15 22:11:04 Magesh Kumar set messages: +
2016-02-15 21:13:54 mrabarnett set messages: +
2016-02-15 19:40:28 Magesh Kumar set messages: +
2016-02-15 19:39:26 Magesh Kumar set messages: +
2016-02-15 19:28:14 mrabarnett set messages: +
2016-02-15 19:14:58 Magesh Kumar set messages: +
2016-02-13 00:44:14 ezio.melotti set status: open -> closedsuperseder: re.sub confusion between count and flags argsmessages: + resolution: not a bugstage: resolved
2016-02-13 00:43:01 mrabarnett set messages: +
2016-02-13 00:19:24 Magesh Kumar create