2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptで文字列をパスカルケース/キャメルケースからスネークケースに変換する

Posted at

既出だったらすいません
くだらないことだから誰も書かないし話題にもならないのかもしれない
ANTON072さんのキャメルケースに変換するの逆を行う

var str = "JavaScript";//サンプル文字
  
str.replace(/^[A-Z]/,function(mached){return mached.toLowerCase()}).replace(/[^^][A-Z]/g,function(matched){return matched.charAt(0)+"_"+matched.charAt(1).toLowerCase()})  
// java_script

見やすくしようとすると以下

str.replace(/^[A-Z]/,
    function(mached){
        return mached.toLowerCase()
    }
).replace(/[^^][A-Z]/g,
    function(matched){
        return matched.charAt(0)+"_"+matched.charAt(1).toLowerCase()
    }
)  
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?