如何用Xceed Docx替换使用regex的单词



我在一个word文档中有多个单词,它们都以"&";,例如CCD_ 1。我正在尝试用一个空字符串替换所有这样的出现。我该怎么办?我在下面试了一下,但什么也没发生。我正在使用免费版本。

using (DocX document = DocX.Load("Example.docx"))
{
String pattern = Regex.Escape("$") + ".+" + Regex.Escape("$");
document.ReplaceText(pattern, "",false, RegexOptions.IgnoreCase);
}

尝试以下模式:$.+?$在你的代码中,它看起来像:

String pattern = Regex.Escape("$") + ".+?" + Regex.Escape("$");

OK看起来像ReplaceText在使用regex时需要一个函数。我让它工作

string WordCheck(string find)
{
return "";
}
String pattern = Regex.Escape("$") + ".+?" + Regex.Escape("$");
document.ReplaceText(@"$.+?$",WordCheck,false, RegexOptions.IgnoreCase);

最新更新