Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to change case with String.replaceAll()

807605Jun 13 2007 — edited Jun 14 2007
Is 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2007
Added on Jun 13 2007
11 comments
1,652 views