Remove all content (text, images, graphs etc.) between two tags - tags could be also inline - word, java

Hi Guys,

I’m looking for a solution how to remove all content (text, images, graphs etc.) between two tags which looks like below:

[if: tag_name]

sample text, sample text

[/if: tag_name]

Tags could be also inline:

[conditional: tag_name] sample text, sample text [/conditional: tag_name]

Look that the end tag contains slash “/”.

Start tag and end tags could have spaces so it causes that start tag and end tag is builded with 2-3 Nodes (Runs).

I’m looking for a solution in Java. Do you have some examples which could help me to solve my problem. I was looking a similar solution on github but could not find solution which is solving similar problem.

Thanks in advance for any help.

@olssonpl

In your case, we suggest you following solution.

  1. Please find the start and end tag using find and replace feature.
  2. Bookmark the content.
  3. Find the first tag and insert BookmarkStart node.
  4. Find the end tag and insert BookmarkEnd node.
  5. Remove the bookmark’s content using Bookmark.Text property by setting its value to empty string.

Please read the following articles.
Find and Replace
Working with Bookmarks