toCamelCaseByDelimiters

fun String.toCamelCaseByDelimiters(delimiters: Regex = CAMEL_DEFAULT_DELIMITERS_REGEX, numberSeparator: String = "_"): String

Converts a string into lowerCamelCase using delimiters.

  • Splits this string matching given delimiters regular expression (by default, via CAMEL_DEFAULT_DELIMITERS_REGEX - any characters that are not letters or digits).

  • If the string does not contain any letters or numbers, it remains unchanged.

  • Places underscore ("_") between consecutive numbers (that were split before).

  • The first word remains in lowercase, and subsequent words are capitalized.

Default behavior (with CAMEL_DEFAULT_DELIMITERS_REGEX):

"hello_world" -> "helloWorld"
"HelloWorld" -> "helloWorld"
"json.parser.Config" -> "jsonParserConfig"
"my.var_name test" -> "myVarNameTest"
"thirdColumn" -> "thirdColumn"
"someHTMLParser" -> "someHtmlParser"
"RESTApi" -> "restApi"
"OAuth2Token" -> "oAuth2Token"
"GraphQLQuery" -> "graphQlQuery"
"TCP_3_PROTOCOL" -> "tcp3Protocol"
"123hello_world456" -> "123HelloWorld456"
"API_Response_2023" -> "apiResponse2023"
"UPPER_case-LOWER" -> "upperCaseLower"
"12parse34CamelCase" -> "12Parse34CamelCase"
"snake_case_example" -> "snakeCaseExample"
"dot.separated.words" -> "dotSeparatedWords"
"kebab-case-example" -> "kebabCaseExample"
"MIXED_Case_with_123Numbers" -> "mixedCaseWith123Numbers"
"___!!!___" -> "___!!!___"
"1000.2000.3000" -> "1000_2000_3000"
"UPPERCASE" -> "uppercase"
"alreadyCamelCased" -> "alreadyCamelCased"
"justNumbers123" -> "justNumbers123"
"Just_Special$Chars!!" -> "justSpecialChars"
"singleword" -> "singleword"
"word_with_underscores_and-dashes" -> "wordWithUnderscoresAndDashes"
"10-20-aa" -> "10_20Aa"

Return

the formatted string in lowerCamelCase.