Saturday 27 August 2011

java.lang.IllegalArgumentException: Illegal group reference, replaceAll and dollar signs

Was getting java.lang.IllegalArgumentException: Illegal group reference when using string.replaceAll() with a replace value which includes dollar signs ($). Dollar signs have special significance in regular expressions so have to be escaped both in the expression and replacement string, denoting a back-reference. See this link for a fuller explanation: http://cephas.net/blog/2006/02/09/javalangillegalargumentexception-illegal-group-reference-replaceall-and-dollar-signs/

No comments:

Post a Comment