Javascript regexp用于大写字符串中a,b或c的任何出现

asu*_*and 0 javascript regex

我想做一个可以映射的字符串替换

catch the ball 
Run Code Online (Sandbox Code Playgroud)

CAtCh the BAll
Run Code Online (Sandbox Code Playgroud)

什么是明确指定a-> A,b-> B和c-> C的正确语法?

Roc*_*mat 6

只需使用.replace()并使用一个函数来大写找到的匹配项.

var str = 'catch the ball';
str.replace(/[abc]/g, function(match){
    return match.toUpperCase();
});
Run Code Online (Sandbox Code Playgroud)