-4
这是一条线,我写来改变字符串为大写的第一个字符,为什么不工作?为什么在调用字符串中的字符时不能替换工作?
var before = "thisString";
var after = before.replace(/before[0]/i, before[0].toUpperCase());
console.log(after);
// output - thisString
我预计输出ThisString。 由下面线更换线上的两个工作 before.replace(/ T/I, “T”); 如果这个工作,为什么不工作。
'/ [0]之前/''的 “before0”'字符串没有别的 – Aaron
相匹配的第一个字符正则表达式是''/^./。 – deceze
如果你真的想用'.replace做到这一点()'有一个在建的正则表达式是没有意义的。 'before.replace(之前[0],[0] .toUpperCase()之前)' – JJJ