Python正則表達式的專家!我正在嘗試在xml文檔中更改一行。 原線爲:使用Python正則表達式查找/替換文檔中的URL
<Tag name="low" Value="%hello%\dir"/>
我想看到的結果是:
<Tag name="low" Value="C:\art"/>
我未能直接的嘗試是:
lines = re.sub("%hello%\dir"", "C:\art"/>
這是行不通的。不會更改文檔中的任何內容。有什麼%?
出於測試目的,我想:
lines = re.sub("dir", "C:\art", a)
我也得到:
<Tag name="low" Value="%hello%\C:BELrt"/>
的問題是,\ A = BEL。
我試了一堆其他的東西,但無濟於事。我該如何解決這個問題?
你確定你需要正則表達式嗎?看起來你可以通過簡單的[replace()](http://docs.python.org/library/stdtypes.html#str.replace)方法調用? – ernie