Skip to content
Advertisement

Replace capital letter with underscore + lowercase letter in Java?

Is there a way to use RegEx in Java to replace all capital letters with an underscore and the same letter only lowercase?

Example: getSpecialString -> get_special_string

Advertisement

Answer

Just try with:

"getSpecialString".replaceAll("([A-Z])", "_$1").toLowerCase();
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement