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();
test.setMatchCase(false);
// 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!