我有原始HTML,正在尝试从输出字符串中删除整个块,例如[%~as..abcd~%]。使用python的re库
teststring = "Check the direction . [%~ MACRO wdwDate(date) BLOCK;
SET tmpdate = date.clone();
END ~%] Determine if both directions."
cleanM = re.compile('\[\%\~ .*? \~\%\]')
scleantext = re.sub(cleanM,'', teststring)
代码中有什么错误
你的模式应该是
.
匹配除新行以外的任何字符,S
允许匹配新行您需要使用
[\S\s]*
而不是.*
,并且可以省去编译:相关问题 更多 >
编程相关推荐