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?

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.