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) *  |
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) *  |
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) *  |
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) *  |
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. :-) |
|
|