Removing text between two fixed words

Hi everyone

I was wondering if it is possible to remove text between two fixed words in a microsoft word document? The text between the words is subject to change, therefore the two words as “start” and “end” of the removal. For an example, see picture below, the start and end words are marked with red.

I saw a very similar question, but it was not answered and it seems like the threat has stopped because the original poster has not responded to some questions asked some time ago. I hope it is okay to post this question.

Thank you for your time, I look forward to hearing from you.

Hi
Welcome to uipath community
Yah that’s possible
Use a word application scope and for that install uipath.word.activities from design tab-> manage packages-> official tab → search for above package And install it
—once after installing use word application scope and pass the file path as input
—inside the scope use read activity and get the output with a variable of type string named str_input
—and now use a assign activity like this
str_output = System.Text.RegularExpressions.Regex.Replace(str_input,”(?<=Rob_removetext1).*(?=Rob_removetext2)”,””)

Hi Palaniyappan

Thank you for your answer. I have tried to apply it and play a bit around with it but I cannot seem to get it to work. The sequence runs without errors, but the text is not removed in the word document.

Picture below is my sequence

Can you see what I am doing wrong?
Once again thank you for your time.

kindlly include this in the expression
str_output = System.Text.RegularExpressions.Regex.Replace(str_input,”(?<=Rob_removetext1).*(?=Rob_removetext2)”,””,RegexOptions.IgnorePatternWhitespace)

and after this
use a new WORD APPLICATION SCOPE , with new file path and use APPEND TEXT activity and pass the above string variable as input

Cheers @Nicklas

1 Like

Hi again

Now it works, the text is removed but there is another little problem. The formatting of the text is also removed. The picture below shows the old and the new text compared to each other

In a small document this is easy to fix but it is a bit difficult if I want to use this in a bigger document.
I have tried to use “word replace” and that works wonders, but the 255 character limit makes it difficult to use for longer text.

But thank you so far for your help. It is really appriciated :slight_smile:

1 Like