把字符串大小写切换的方法

var str = '$a1a2a_B3B4B$';

function transformCode(code) {
    return code.replace(/([A-Z])|([a-z])/g, function(match, $1, $2) {
        if ($1) {
            return $1.toLowerCase();
        } else if ($2) {
            return $2.toUpperCase();
        }
    });
}

猜你喜欢

转载自www.cnblogs.com/xiaoyucoding/p/12552265.html
今日推荐