We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Range replace problem with brackects

I want to replace all text in a document between square brackets with empty string.

I think that its possible only with my own IReplacingCallback handler so I implement one. After that I call the range.replace on Document with this Regex: "\[(.*)\]"
My problem is that it fires my handler only the first occurance of matched pattern not all occurances. I’ve already checked my regex pattern with RegEx.Replace and its successfully replace all occurances.
Can you tell me why Aspose.Words not fires IReplacingCallback handler for all matched pattern at all?
Hi Peter,

Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Best regards,

Attached you find the document.

Hi Peter,


Thanks for your inquiry. Please use the following code snippet to replace all text in a document between square brackets with empty string:

Document
doc = new Document(@“C:\Temp\ASPOSE_Test.doc”);

doc.Range.Replace(new Regex(@"(?<=\[)(.*?)(?=\])"), string.Empty);

doc.Save(@"C:\Temp\out.doc");


I hope, this helps.

Best regards,