给定一个单词,你需要判断单词的大写使用是否正确。
我们定义,在以下情况时,单词的大写用法是正确的:
/** * @param {string} word * @return {boolean} */ var detectCapitalUse = function(word) { // 第一种是全部为大写字母 第二种是 首字母大写 其他小写 第三种的全部为小写字母 // 满足其一则为true return /^[A-Z]+$/.test(word) || /^[A-Z][a-z]+$/.test(word) || /^[a-z]+$/.test(word); };
原文:https://www.cnblogs.com/lanpang9661/p/12886524.html