This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
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 <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'
========================================================================
|
|||
| 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><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'
========================================================================
|
|||
| 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 '<root>', 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 (<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. |
|||
| msg260331 - (view) | Author: Magesh Kumar (Magesh Kumar) | Date: 2016年02月15日 19:40 | |
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. |
|||
| 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: + msg260335 |
| 2016年02月15日 21:13:54 | mrabarnett | set | messages: + msg260334 |
| 2016年02月15日 19:40:28 | Magesh Kumar | set | messages: + msg260331 |
| 2016年02月15日 19:39:26 | Magesh Kumar | set | messages: + msg260330 |
| 2016年02月15日 19:28:14 | mrabarnett | set | messages: + msg260329 |
| 2016年02月15日 19:14:58 | Magesh Kumar | set | messages: + msg260328 |
| 2016年02月13日 00:44:14 | ezio.melotti | set | status: open -> closed superseder: re.sub confusion between count and flags args messages: + msg260220 resolution: not a bug stage: resolved |
| 2016年02月13日 00:43:01 | mrabarnett | set | messages: + msg260219 |
| 2016年02月13日 00:19:24 | Magesh Kumar | create | |