在格式错误的XML的注释中匹配双连字符

Pir*_*iel 5 regex pcre autoit

我将解析不符合" 注释中没有双连字符 "的标准的XML文件,这使得MSXML抱怨.我正在寻找一种删除违规连字符的方法.

我在用StringRegExpReplace().我试图遵循正则表达式:

<!--(.*)--> : correctly gets comments
<!--(-*)--> : fails to be a correct regex (also tried escaping and using \x2D)
Run Code Online (Sandbox Code Playgroud)

鉴于正确的模式,我会打电话:

StringRegExpReplace($xml_string,$correct_pattern,"") ;replace with nothing
Run Code Online (Sandbox Code Playgroud)

如何在XML注释中匹配剩余的连续连字符,同时保留剩余的文本?

Tim*_*ker 3

(?<!<!)--+(?!-?>)(?=(?:(?!-->).)*-->)
Run Code Online (Sandbox Code Playgroud)

仅在和之间匹配--(或----等)。您需要设置参数以允许点匹配换行符。<!---->/s

解释:

(?<!<!)--+(?!-?>)(?=(?:(?!-->).)*-->)
Run Code Online (Sandbox Code Playgroud)

在 regex101.com 上进行实时测试。

我想正确的 AutoIt 语法是

StringRegExpReplace($xml_string, "(?s)(?<!<!)--+(?!-?>)(?=(?:(?!-->).)*-->)", "")
Run Code Online (Sandbox Code Playgroud)