我想做一个可以映射的字符串替换
catch the ball
至
CAtCh the BAll
显式指定 a->A、b->B 和 c->C 的正确语法是什么?
最佳答案
只需使用 .replace()
并使用函数将找到的匹配项大写。
var str = 'catch the ball';
str.replace(/[abc]/g, function(match){
return match.toUpperCase();
});
关于Javascript 正则表达式将字符串中出现的任何 a、b 或 c 大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21392080/