What my dog really hears My dog is called Rex. Every time I scold him, he seems not very impressed and the only times I see him react is when I pronounce his name. If I say 

Rex, I told you not to do this! You're making me angry Rex!

all he hears is 

Rex, * **** *** *** ** ** ****! ***'** ****** ** ***** Rex!

The challenge : given an input string, your program must output the same string where all alphabetic characters have been turned to stars, except the characters in the appearances of the word Rex, who must be left untouched. The non-alphabetic characters are also left untouched.

Details : The challenge is case-insensitive, thus rex must be left untouched also. The word Rex can be part of another word, so for example anorexic must be rendered as ***rex**.

Update : as the initial text of this challenge did not clarify how underscores or numbers or accentuated characters should be treated, I do not make any special requirement on those characters. Thus, a solution is valid as long as characters in a-zA-Z (and also the one mentioned in the examples, ,!".) are handled correctly.

Test cases :

Input : Rex lives in Rexland. 

Output : Rex ***** ** Rex****.

Input : To call Rex, just say "Rex". 

Output : ** **** Rex, **** *** "Rex".

Input : My cat is getting anorexic. 

Output : ** *** ** ******* ***rex**.
**REXX 151 148 141 bytes **

(Kinda seemed appropriate)

i=arg(1)
m=i
o=translate(m,'',xrange('A','z'),'*')
p=0
do forever
   p=pos('REX',m,p+1)
   if p=0 then leave
   o=overlay(substr(i,p,3),o,p)
end
say o


Try it here

Notes for non-REXXers:


translate is a character replacement function (name comes from an assembler instruction on IBM MF).  It searches string1 for the characters in string3. Every time it finds one it replaces it with the same positioned one in string2. If string2 is too short it is padded with the pad character.


See here for translate function


overlay simply overlays the string1 on top of string2 at the specified position. 


See here for overlay function