Please advise me use replace API

I have attached a word document with the query as the content. Please refer and advise me. Thanks in advance.


Thanks for your inquiry. The problem is in your regular expression. Please try using this one:

Document doc = new Document("C:\\Temp\\in.doc");
Pattern p = Pattern.compile("<]*>>");
doc.getRange().replace(p, "New Value");"C:\\Temp\\out.doc");

Best regards,

Thanks for your quick response which works great. However I face another problem. I have two special characters to be used in the regex. I tried

Pattern p = Pattern.compile("½[^>]*╗");

The characters are special not simple greater than and lesser than symbols.Now its throwing some exception like,

Exception in thread “main” java.lang.UnsupportedOperationException: The match includes one or more special or break characters and cannot be replaced.

at com.aspose.words.acc.a( 213)
at com.aspose.words.acc.Nn( 171)
at com.aspose.words.Range.replace( 123)

Wehreas java returns true
for the following statement,

Pattern.matches("½[^>]*╗", "½aaa╗½bbb╗")

Is there any work around to solve this? Please advise. Thanks in advance.


Thanks for your inquiry. Captured and replacement strings cannot contain special characters. An exception is thrown if a captured or replacement string contain one or more special characters: paragraph break, cell break, section break, field start, field separator, field end, inline picture, drawing object, footnote.
You should take this in account while building the template.
Also, if you need to fill the document with data, I do not think that find/replace is the best option. I think the best option in this case is Mail Merge:
Best regards.

This is really good. How to pass the data source as from an XML file or any other object other than a DB Table. In my requirement, we have the result as an XML object which need to execute in a mail merge with region.


Thanks for your inquiry. I think, you can use IMailMergeDatasource to achieve what you need:
Hope this help. Please let me know if you need more information, I will be glad to help you.
Best regards,