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

Free Support Forum - aspose.com

Delete multiple tag occurance

Hi,

I am trying to find a tag in a document and delete its occurances.Can you please help me on this.

I have attached sample Document in which i have to delete tag $$$WAP START{ }WAP END$$$

Aspose Sample.docx (15.1 KB)

Hi @NanthiniSenthil123,
We appreciate your interest in Aspose products.

You can use the find and replace functionality provided by the API. The Replace method accept plain text or RegEx as parameter to replace, for your particular case I recommend to use a RegEx to capture all the text in between the open and closing tags, you can check the following example:

// Load the document.
Document doc = new Document("C:\\Temp\\Aspose Sample.docx");

// Replace all tag occurrences that follow the required pattern.
// The following RegEx also remove the Tag quotes, to replace only the content of the Tag the RegEx to use will be (?<=\\$\\$\\$WAP START\\{)(.*?)(?=\\}WAP END\\$\\$\\$).
doc.Range.Replace(new Regex("\\$\\$\\$WAP START\\{(.*?)\\}WAP END\\$\\$\\$"), string.Empty);

// Save the changes in a new file.
doc.Save("C:\\Temp\\Aspose Sample Cleared.docx");

Please let me know if you need assistance with something else.
Best regards.