I am looking at http://www.w3schools.com/jsref/jsref_replace.asp and the specific example at: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_replace3

var str="Mr Blue has a blue house and a blue car";
var n=str.replace(/blue/gi, "red");

And the result of N would be:

 Mr red has a red house and a red car 

I want the result to be:
Mr Red has a red house and a red car

With the first-replaced occurance to be capitalized like the original text to be replaced.

Is there a way to do this?

5 Years
Discussion Span
Last Post by pritaeas

I think you can only do that if you pass a replace function. You cannot do it with a single replace string in this case, and Javascript regex does not accept arrays as parameters (unlike PHP).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.