19
rated 0 times
[
26]
[
7]
/ answers: 1 / hits: 71931
/ 13 Years ago, thu, may 26, 2011, 12:00:00
I'd like to know how to replace a capture group with its uppercase in JavaScript. Here's a simplified version of what I've tried so far that's not working:
> a=foobar
'foobar'
> a.replace( /(f)/, $1.toUpperCase() )
'foobar'
> a.replace( /(f)/, String.prototype.toUpperCase.apply($1) )
'foobar'
Would you explain what's wrong with this code?
More From » regex