How to change case with String.replaceAll()
807605Jun 13 2007 — edited Jun 14 2007Is it possible to use regex replacing feature (String.replaceAll or Matcher.replaceAll) with change to upper or lower case?
For example I have the input text:
-aaa- -bbb-
I want to change the hyphens to underscore, and change text inside to upper case.
The first thing is easy:
String.replace("-(.*?)-", "_$1_")
but how to change text inside $1 to upper case (or lower, if needed)?
I would like to have an option to write replacement regex like for example "_$+1_" where $+1 means "$1 with change to upper case" - but obviously there is no such option.
Obviously, I can write my own method being able to parse the syntax like this.
But perhaps there is such functionality already implemented? Do you know how to solve it?