We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Replace multiline text between Start and End tags

Hi, we have a document template which has multiple option tags with text. The text inside the option tags along with the option tag will be deleted based on the condition. For example, in the attached template, we have 3 options. If the condition met the first option, the rest of the options text along with the tag should be deleted. We have tried the find and replace with regex options, but unable to get the text inside the tags.

TextSelection[] textSelections1 = doc.FindAll(new Regex(@"<Option1>(.+?)</Option1>", RegexOptions.Multiline));

TextSelection[] textSelections2 = doc.FindAll(new Regex(@"<Option1>(.*)</Option1>", RegexOptions.Multiline));

Please help us how to perform this.

Attachment: POC_Sample_Document_fb7206d1_8fd34253.zip

1 Reply

SB Suriya Balamurugan Syncfusion Team March 9, 2023 02:36 PM UTC

Hi Ramaswamy,

From the given details, we have found that your requirement is to find and replace multiline text between start and end tags using Regex.

To achieve your requirement, we suggest you to use the FindSingleLine API in the Word document to find the multiple paragraph text using Regex as text selections and then remove the paragraphs of the selected text along with the tag.

have prepared the sample application to find and replace multiline text between start and end tags using Regex as per your requirement and it can be downloaded from the below attachment.

Refer our UG documentation to know more about FindSingleLine API,

Suriya Balamurugan.

If this post is helpful, please consider accepting it as the solution so that other members can locate it more quickly.

Attachment: Replacemultilinetext_a8ff50d7.zip

Live Chat Icon For mobile
Up arrow icon