Removing multiple occurance of a string pattern (String that starts and ends with a particular pattern) in a document

Hi Aspose Team,

I am having problem in removing multiple occurance of a string in a word document.

For instance, the following text is in any XYZ.docx document,

Hello This a test String. Guidance dnvnhjlmnmvhctd ajjdkb ;.nnsh EndGuidance.;;';lp Hello This a test String. Guidance dnvnhjlmnmvhctd ajjdkb ;.nnsh EndGuidance ABC

I want to remove all occurance of strings that starts with "Guidance" and ends with "EndGuidance". Hence my desired output document should have the following text :

Hello This a test String. .;;';lp Hello This a test String. ABC

I have used the below code snippet:

string strPattern = "Guidance.+?EndGuidance";
Regex objRegex = new Regex(strPattern, RegexOptions.Singleline);

Document doc1 = new Document(@"SomeDrive\AnyFolder\XYZ.docx");
doc1.Range.Replace(objRegex, "");

However Document.Range.Replace() is throwing an exception thats goes like this :

The match includes one or more special or break characters and cannot be replaced.

Important Observation:

When I used the same REGEX to replace the same string pattern from a string object, it got me the desired result. However I want to do the same in Document.

string strTest = "Hello This a test String. Guidance \n dnvnhjlmnmvhctd ajjdkb ;.nnsh EndGuidance.;;';lp Hello Tis a test String. Guidance dnvnhjlmnmvhctd ajjdkb ;.nnsh EndGuidance";

string result = Regex.Replace(strTest, @"Guidance.+?EndGuidance", "", RegexOptions.Singleline);

Please let me know about the way forward !

Hi,


Thanks for your inquiry. We tested the scenario and have managed to reproduce the same exception on our end. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-12078. Our product team will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-12078) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.