wanting a javascript regex notation for replacing cases
eg
I want to write a camelToSnake()
camelToSnake = (phrase) ->
return phrase.replace(/([A-Z])/g, /-L$1/)
is there such options
你可以使用这个代码:
var s = 'camelToSnake';
var r = s.replace(/([A-Za-z])/g, function ($0, $1) { c=$1.charAt(0);
return (c==c.toUpperCase())?c.toLowerCase():c.toUpperCase(); } );
//=> CAMELtOsNAKE
链接地址: http://www.djcxy.com/p/21266.html
上一篇: Android构建错误:未知的包过滤器