We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Tag inside table in MSWord is not replacing


We use java aspose.words to find all occurrences of a character pattern specified by a regular expression and calls a user defined(TagReplacer.java) replace evaluator method. But the tag inside table in MSWord is not replacing by the replacing() methode.

//This is my sample code in main methode,
Pattern pattern = Pattern.compile(“\{JS: ([^\t\n\r\f\v>]+)}”, Pattern.CASE_INSENSITIVE);
Document doc = new Document(“TestFile.doc”);
doc.getRange().replace(pattern, new TagReplacer(), false);

//TagReplacer is an another java file
public class TagReplacer implements IReplacingCallback {
public int replacing(ReplacingArgs e){
Node currentNode = e.getMatchNode();
DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
String replacedStr = e.getMatch().group(1); // expected value as ‘Old valueC1R1’… from TestFile.doc
builder.write(“New value of ”+ replacedStr);

Attached the screen shot of TestFile.doc table(with paragraph marks), Table in TestFile.jpg (14.0 KB)
Also attached the TestFile.doc in zipTestFile.zip (5.9 KB)



Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17278. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-17278) as ‘Not a Bug’.

You are using obsolete method of Range.Replace. Please use Range.Replace method (Regex, String, FindReplaceOptions) to replaces all occurrences of a character pattern specified by a regular expression with another string.

Please use following regular expression to get the desired output. Hope this helps you.

String input = "{JS: Old valueC1R1}{JS: Old valueC2R1}{JS: Old valueC1R2}{JS: Old valueC2R2}{JS: Old valueC1R3}{JS: Old valueC2R3}";
Pattern pattern = Pattern.compile("\\{JS(?:(?!\\{JS).)*.}", Pattern.CASE_INSENSITIVE);

FindReplaceOptions opt = new FindReplaceOptions();
FindReplaceTest replacingCallback = new TagReplacer();

doc.getRange().replace(pattern, "", opt);