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

Free Support Forum - aspose.com

Aspose Currency replacement Issue

Hello Aspose Java Team,

I am using Java Aspose api for word document. I am trying to replace the text Keyword “CURRENCY” in word document with the text “AUD $”.
Below is the sample code which I wrote for text replacement logic.

import com.aspose.words.Document;
import com.aspose.words.FindReplaceOptions;

public class ReplaceText
    public static void main(String[] args) throws Exception
        String dataDir = "E:\\Project\\Sprint 19\\Test_Aspose_Doc\\";
        Document doc = new Document("E:\\Project\\Sprint 19\\Test_Aspose_Doc\\3DS WW TM SOW Template - V1.9.docx");
        FindReplaceOptions test = new FindReplaceOptions();
        //      doc.getRange().replace("CUST_ENTITY", "Sample Text Replcement",test);
        doc.getRange().replace("CURRENCY", "AUD $",test);
        doc.save(dataDir + "Final_Replace_Text.docx");
        System.out.println("Process Replace Completed...............");

It is working fine for the commented line doc.getRange().replace(“CUST_ENTITY”, “Sample Text Replcement”,test); but when it comes for doc.getRange().replace(“CURRENCY”, “AUD $”,test);.
It gives the following issue -

Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference: group index is missing
	at java.base/java.util.regex.Matcher.appendExpandedReplacement(Matcher.java:1030)
	at java.base/java.util.regex.Matcher.appendReplacement(Matcher.java:998)
	at java.base/java.util.regex.Matcher.replaceAll(Matcher.java:1182)
	at com.aspose.words.internal.zzqF.zzW8N(Unknown Source)
	at com.aspose.words.internal.zzYuu.zzX91(Unknown Source)
	at com.aspose.words.zzZpn.zzZNf(Unknown Source)
	at com.aspose.words.zzZpn.zzXUG(Unknown Source)
	at com.aspose.words.zzZpn.zzXUG(Unknown Source)
	at com.aspose.words.zzZpn.zzYIX(Unknown Source)
	at com.aspose.words.Range.replace(Unknown Source)
	at com.anil.combine.ReplaceText.main(ReplaceText.java:19)

I need help regarding this issue. Please let me know If am doing anything wrong.

Thanks in advance!

1 Like

@ketanpbh can you please attach your source Word document to try to replicate your issue?

@ketanpbh The problem might occur because UseSubstitutions option is enabled in FindReplaceOptions:

FindReplaceOptions test = new FindReplaceOptions();

In this case $ is used for referring groups in the regular expression.

FYI @eduardo.canal

1 Like

hello @eduardo.canal ,

Thank you. test Doc.docx (102.8 KB)

Please find the sample document…

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSJAVA-2840

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@alexey.noskov Where and how to track the Issue ID(s): WORDSJAVA-2840 ?

@ketanpbh You can track the issue status here in this topic. You can see it at the bottom of the page.


The reason for this behavior is that the $ character is a special character in Java. You need to change the line as follows:

doc.getRange().replace("CURRENCY", "AUD //$");