• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Why does this fail?

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a simple regex which throws: [java.lang.IllegalArgumentException] Illegal group reference.

The code is simple but I cannot figure out why. I have put String Y in the second post to make it more readable (it contains some XML).




Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:561)
at java.util.regex.Matcher.replaceAll(Matcher.java:661)
at java.lang.String.replaceAll(String.java:1663)
at ReplaceTest.main(ReplaceTest.java:13)

[ March 24, 2005: Message edited by: Kashif Riaz ]
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String y =



[ March 24, 2005: Message edited by: Kashif Riaz ]
[ March 24, 2005: Message edited by: Kashif Riaz ]
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved! It was the dollar sign in the String y:



Thanks for looking.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is just a wild guess: the replacement string can contain group references using the syntax $1, $2, $3... to substitute the 1st, 2nd, 3rd captured group. Dollar signs have to be escaped to be included literally.

You don't have any dollar signs, but you do have a tag "<settcurr>�!</settcurr>". I wonder if any currency symbol can be used in place of "$"? If so, then perhaps "�!" is a currency symbol (it doesn't render correctly in my browser, so I don't know what it is), and so you've got the invalid captured group reference "�!<". You can try escaping the currency symbol by inserting "\\" into the String right before it.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic