A: 
$("div, p, span").each(function(){
  var o = $(this);
  o.html(o.text().replace(/tests?/gi, function($1){
     return($1.toUpperCase() + '®');
  }));
});

for instance.

Kind Regard

--Andy

jAndy
That works but it is the same problem as my original. The ones that already have the ® have 2 ® 's after the replacement.
ngreenwood6
A: 

The tricky part here is to match the ®, which is a Unicode character, I guess... Have you tried the obvious?

var newStr = str.replace(/test(s)?®?/gi, function(m, s1){
  var s = s1?s1.toUpperCase():"";
  return "TEST"+s+"®";
});

If the problem is that ® does not match, try with its unicode character number:

/test(s)?\u00ae/

Sorry if the rest does not work, I assume your replacement already works and you just have to also match the ® so that it does not get duplicated.

Victor
doesnt seem to be working. does it work for you?
ngreenwood6
A: 

Instead of creating something from scratch try using an alternate library. I develop with PHP so using a library that has identical methods in JavaScript is a life saver.

PHP.JS Library

var newReplaced = $P.str_replace("find","replace",varSearch);

Brant
-1 (you just can't see it... cause I'm out of votes). Self promoting is always bad, but yours is terrible.
Coronatus
I use this library in conjunction with jQuery. No real problems.
Brant
+1  A: 

To expand on jAndy's answer, try this:

 $("div, p, span").each(function(){
  o = $(this);
  o.html( o.text().replace(/test(|s)\u00ae/gi, function($1){
     return($1.toUpperCase());
  }));
 });

Using the code you provided, try this:

$(document).ready(function(){
 $('body').html( $('body').html().replace(/realtor(|s)\u00ae/gi, function($1){
  return($1.toUpperCase() );
 }));
})
fudgey
that works great the only problem is that if there is no ® at the end (for example realtor) it doesnt add the ® in there. I need it to do that. Any ideas?
ngreenwood6
Gave you a plus one because you helped actually get the solution.
ngreenwood6
The way your question is written it seems that the ® is already there, so this replace function will find all instances of realtor® or realtors® and make it uppercase, so you don't need to add another "®". Anyway, glad you have your solution and thanks for the upvote.
fudgey
+1  A: 

As others have already said, you will not be able to match the ®, you need to match on
\u00ae.

The code you provided needs to be changed to:

var html = $('body').html();
var html = html.replace(/realtor(s)?(\u00ae)?/gi, function(m, s1, s2){
    var s = s1?s1.toUpperCase():"";
    var reg = s2?s2:'®';
    return "REALTOR"+s+reg;
});
$('body').html(html);
David_001
Thank you taht worked perfectly.
ngreenwood6