python - Replacing an xml tag with regex -
i utilize lxml parse xml, in case, need alter content of single tag.
<sales_start_date>yyyy-mm-dd</sales_start_date>
yyyy-mm-dd variable date.
how replace above to:
<sales_start_date>2013-01-01</sales_start_date>
here have (which sort of works)
re.sub('<sales_start_date>[\d-]+</sales_start_date>', '<sales_start_date>2013-01-01</sales_start_date>', data)
since know exact tags, pretty simple, grab character until next tag (any character not <
):
re.sub('<sales_start_date>[^<]+</sales_start_date>', '<sales_start_date>2013-01-01</sales_start_date>', data)
python regex
No comments:
Post a Comment