LoginSignup
0
0

More than 5 years have passed since last update.

Scalaでキャメルケースをスネークケースに変換する

Last updated at Posted at 2018-12-14

ぐぐったコードが数字が入ったり大文字連続だったりのイレギュラーケースで壊滅状態だったので今さっきでっち上げてみた。

StringHelper.scala
object StringHelper {

  private val separatees = "[a-z](?=[A-Z])|[0-9](?=[a-zA-Z])|[A-Z](?=[A-Z][a-z])|[a-zA-Z](?=[0-9])".r

  def camel2Snake(s: String): String = separatees.replaceAllIn(s, _.group(0) + '_')
    .toLowerCase
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0