This project has moved and is read-only. For the latest updates, please go here.

Replacing text with wildcard

Aug 10, 2015 at 11:30 PM
Edited Aug 11, 2015 at 5:19 PM
document.ReplaceText is working fine for simple search/replace. However, I need to do a search and replace with a wildcard.

This is possible in Word itself by selecting the "use wildcard" option in the search/replace dialog box.

Is this functionality possible with the DocX library?


EDIT: Basically, I need to delete all text between two markers in the text. The text can be anything but the starting and ending marker is fixed text. For example, I want to delete the second block in my word document:

[block1]This is the first block of text.
I want to keep it.[/block1]
[block2]This is the second block of text.
I want to be able to delete everything
between the block 2 tags.[/block2]

I want to replace "[block2]*[/block2]" with "". This is easy to do within Microsoft Word itself. I just can't figure out how to do it with the DocX library.
Aug 13, 2015 at 6:53 PM
Edited Aug 13, 2015 at 7:11 PM
I thought I could possibly do this with something like:
List<string> mylist;
mylist = document.FindUniqueByPattern("\[block2\](.|\n)*\[/block2\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);
I'm trying to find using a wildcard, then I'll feed the result of this into the document.ReplaceText function.

It works great... as long as the pattern is within a single paragraph. So, using the pattern it finds this:

[block2]This is the second block of text.[/block2]

But not this:

[block2]This is the second block of text.¶
I want to be able to delete everything¶
between the block 2 tags.[/block2]

I need the second. Any ideas? I'm starting to run out... :(

EDIT: I'm using v1.0.0.18