String titleize when text is separated by others special character than space

Hi guys, I have a specific question. How can I capitalize every first letter of words in a string when it’s separated by something else than space ?

For example, if I have this text:

@kernels-main

I would like it become:

@Kernels-Main

You can split the process by

  1. Replacing the special char by space
  2. Maybe dropping the @ prefix
  3. Converting to titleize
  4. Replace space by special char back
  5. Prefix with @

At least until you need more performance I would start with that.

1 Like

Something like this works:

"@kernels-main".gsub(/[@-]([^@-]+)/) do |piece|
   piece[0] + piece[1..].titleize
end
1 Like