Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
brpaula_
Contributor
Contributor

replaceAll with special caracter '$' error

Hi There!!!

 

I have an error related to 'replaceall' and the special character '$'.

 

I have a conetxt variable that receives a text from the database. Part of this text there is the character '$' which is part of the text. Ex: R$.

 

When I try to use 'replaceall' and replace a information with the content of this variable it is returning the error 'java.lang.IllegalArgumentException: Illegal group reference'.

 

I sow that the special caracter '$' with 'replaceall' cause this error.

 

How can I correct this error without having to delete the special character from the text?

 

0695b00000kXbWZAA0.png 

Error:

Exception in component tMap_2 (TESTE_EMAIL_FOLLOW_UP)

java.lang.IllegalArgumentException: Illegal group reference

at java.base/java.util.regex.Matcher.appendExpandedReplacement(Matcher.java:1068)

at java.base/java.util.regex.Matcher.appendReplacement(Matcher.java:998)

at java.base/java.util.regex.Matcher.replaceAll(Matcher.java:1182)

at java.base/java.lang.String.replaceAll(String.java:2126)

at savixx_bi.teste_email_follow_up_0_1.TESTE_EMAIL_FOLLOW_UP.tDBInput_3Process(TESTE_EMAIL_FOLLOW_UP.java:10343)

at savixx_bi.teste_email_follow_up_0_1.TESTE_EMAIL_FOLLOW_UP.tDBInput_4Process(TESTE_EMAIL_FOLLOW_UP.java:9516)

at savixx_bi.teste_email_follow_up_0_1.TESTE_EMAIL_FOLLOW_UP.tDBInput_1Process(TESTE_EMAIL_FOLLOW_UP.java:7688)

at savixx_bi.teste_email_follow_up_0_1.TESTE_EMAIL_FOLLOW_UP.runJobInTOS(TESTE_EMAIL_FOLLOW_UP.java:15724)

at savixx_bi.teste_email_follow_up_0_1.TESTE_EMAIL_FOLLOW_UP.main(TESTE_EMAIL_FOLLOW_UP.java:14761)

Labels (2)
3 Replies
Anonymous
Not applicable

Hello @Bruno Rocha​ ,

To fix the issue, you can encode/decode the special char $ in the replacement string before/after the method .replaceAll like the below:

String replacement= (context.eventosProcesso == null? "": context.eventosProcesso);

replacement=replacement.replaceAll("\\$", "US_DOLLAR"); //encode replacement

String resultString=text.replaceAll("eventosProcesso", replacement);

resultString=resultString.replaceAll("US_DOLLAR", "\\$"); //decode replacement

 

Best regards

Aiming

 

Anonymous
Not applicable

Try to use replace instead of replaceAll. ReplaceAll expects a regular expression where certain characters are part of the pattern.

 

So either you accept that your pattern has to be proper regex ( \\$ ) or you simply use replace.

brpaula_
Contributor
Contributor
Author

thanks @Balazs Gunics​ and @Aiming Chen​ ...solved!!!