下面的示例演示了 replace 方法将第一次出现的单词 "The" 替换为单词 "A" 的用法。function ReplaceDemo(){
   var r, re;                    // 声明变量。
   var ss = "The man hit the ball with the bat.\n";
   ss += "while the fielder caught the ball with the glove.";
   re = /The/g;             // 创建正则表达式模式。
   r = ss.replace(re, "A");    // 用 "A" 替换 "The"。
   return(r);                   // 返回替换后的字符串。
}