Issue
If you see java.lang.IndexOutOfBoundsException: No group 2 , when you are doing <String>.replaceFirst(<source string>, <target string>) or <String>.replaceAll(<source string>, <target string>).
Reason
You possibly have "$" character in your target string.
Solution
Add java.util.regex.Matcher.quoteReplacement(<target string>), before you apply replace function.
Bug reported on Sun site by someone.
Monday, October 09, 2006
Java String replace: java.lang.IndexOutOfBoundsException: No group 2
Labels:
Exception,
Java,
regEx,
regular expression,
replace,
replaceAll,
replaceFirst,
String
Subscribe to:
Post Comments (Atom)
1 comment:
Thanks!
Post a Comment