Is there a way to use RegEx in Java to replace all uppercase letters with an underscore and a single letter only in lower case?
Example: getSpecialString→get_special_string
getSpecialString
get_special_string
Just try:
"getSpecialString".replaceAll("([A-Z])", "_$1").toLowerCase();
There is a snakeCase method in underscore-java :
import com.github.underscore.lodash.$; public class Main { public static void main(String[] args) { $.snakeCase("getSpecialString"); // -> get_special_string } }
Source: https://habr.com/ru/post/1540572/More articles:Insert text at cursor position with Quill.js - javascriptWhy the Laravel trashed () method was not found> - phpKnow cache programs - linux'NoMethodError: undefined метод `scan' для nil: NilClass 'при функциональном тестировании с рельсами - rubypacman -Syu does not work: invalid pgp key - pacmanThe difference between Array.prototype.slice.call (arguments) and Array.apply (null, arguments) - javascriptd3.js manual NVD3 trigger hint - javascriptvariable assignment with switch in coffescript - javascriptCreating API documents through code comments - restCannot run shell command via php exec, but can user on shell? - linuxAll Articles