1
我需要用我的字符串替换XML文件中的一些路径。Python正则表达式修改路径
所有要更改的路径都以schemaLocation=
或location=
开头,后跟带扩展名的路径和文件名。
一些例子:
FROM
'schemaLocation="http://docs.oasis-open.org/wsn/b-2.xsd"/>' (1)
or
'schemaLocation=
"http://docs.oasis-open.org/wsn/b-2.xsd"/>' (2)
or
'schemaLocation="b-2.xsd"/>' (3)
TO
'schemaLocation="b-2.xsd"/>' (4) in this sample new path is clear
or
'schemaLocation="../xsd/b-2.xsd"/>' (5) where "../xsd/" is new path
我写
regex = '(?<=schemaLocation=)([\s]*[\r\n]*[\s]*".*[/]?)(?=.+[.]xsd["])'
但我不能修改它从(3)处理(5)。
下面的字符串是你的预期结果吗? –
显然他们是? – trainoasis
@AvinashRaj,是的,这是预期的结果 – Dcow