我想做一个可以映射的字符串替换
catch the ball
Run Code Online (Sandbox Code Playgroud)
至
CAtCh the BAll
Run Code Online (Sandbox Code Playgroud)
什么是明确指定a-> A,b-> B和c-> C的正确语法?
只需使用.replace()并使用一个函数来大写找到的匹配项.
var str = 'catch the ball';
str.replace(/[abc]/g, function(match){
return match.toUpperCase();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33 次 |
| 最近记录: |