I’m trying to delete whole lines from a Writer document which match a pattern like ‘%C%c…%c%C’.
I’m using construct like this:
xTextDocument = (XTextDocument)xComponent;
XReplaceable xReplaceable = (XReplaceable)xTextDocument;
XReplaceDescriptor xReplaceDescriptor = xReplaceable.createReplaceDescriptor();
{
XPropertySet replaceProps = xReplaceDescriptor;
string cStringRegex = @"%C[\s\S]*?%c[\s\S]*?%c[\s\S]*?%C$";
replaceProps.setPropertyValue("SearchRegularExpression", new uno.Any(true));
xReplaceDescriptor.setSearchString(cStringRegex);
xReplaceDescriptor.setReplaceString(string.Empty);
xReplaceable.replaceAll(xReplaceDescriptor);
}
I have the following issues:
-
Code above leaves blank lines
behind, and I don’t want to remove
any more pre-existing blank lines. -
This pattern does match multiline strings from LibreOffice Writer UI, but doesn’t seem to work programmatically.
How do I get it to solve the above conditions?
[PS: I just read about balancing groups in C# Regex, but does LibreOffice have support for this?]