我有一个长字符串i,其中包含<fixtext>XML 文档中标记之间的字符串。我将所有的<and分别>替换为<and并将其存储在一个变量中。当我调试并查看 时,所有的and实例都被正确替换了。>inn<>
然后我搜索一大块需要调用的文本stigData并将i其替换为n.
我知道它正在寻找i,因为<and>在本节的前半部分被替换,但后半部分没有改变。
是否有一个原因?我如何确保它实际上替换了完整的字符串?
fixTexts = re.findall(r"<\s*fixtext[^>]*>(.*?)</fixtext\s*", stigData, flags=re.S)
for i in fixTexts:
n = i.replace(">", ">").replace("<", "<")
stigData = stigData.replace(i, n)
输出示例(in stigData):
<fixtext fixref="F-66463r5_fix">Set the TRUSTWORTHY property OFF; or remove the database owner from the
fixed server role(s); or change the database owner.
ALTER DATABASE <name> SET TRUSTWORTHY OFF;
GO
(more words here)
USE<database name>;
(more words below)
</fixtext>
所需输出(in stigData):
<fixtext fixref="F-66463r5_fix">Set the TRUSTWORTHY property OFF; or remove the database owner from the
fixed server role(s); or change the database owner.
ALTER DATABASE <name> SET TRUSTWORTHY OFF;
GO
(more words here)
USE<database name>;
(more words below)
</fixtext>
谢谢!