Replace a Regex capture group with uppercase in Javascript?

You can pass a function to replace. Var r = a. Replace(/(f)/, function(v) { return v.toUpperCase(); }); Explanation a.

Replace( /(f)/, "$1".toUpperCase()) In this example you pass a string to the replace function. Since you are using the special replace syntax ($N grabs the Nth capture) you are simply giving the same value. The toUpperCase is actually deceiving because you are only making the replace string upper case (Although the return value will still be "$1").A.

Replace( /(f)/, String.prototype.toUpperCase. Apply("$1")) Believe it or not the semantics of this expression are exactly the same.

– Evan Carroll May 26 at 17:57 @Evan Carroll: Please see my answer. – kay May 26 at 17:58 Ah, I see what you mean, I'm upercasing "\$1". Not the result of the voodoo that replace will do that is apparently substituting $1 for the first capture group.

– Evan Carroll May 26 at 18:04.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions