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 !