转自http://www.jb51.net/article/9869.htm

以下代码结果为:FALSE,TRUE,TRUE,请问结果中为什么第一个为FALSE?    

 1 <html>
 2  <head> 
 3  < script language = "javascript" >
 4  function c1() {
 5      re = new RegExp("^\d*$");
 6      alert(re.test("123456"));
 7  }
 8  function c2(form) {
 9      re = new RegExp(form.t2.value);
10      alert(re.test(form.t1.value));
11  }
12  function c3() {
13      re = /^\d*$/;
14      alert(re.test("123456"));
15  }
16  c1();
17  c2(document.form1);
18  c3(); 
19  </script>/ 
20  </head> 
21  <body> 
22   <form name="form1">
23     字符串: 
24    <input name="t1" value="123456" /> 模式:/ 
25    <input name="t2" value="^\d*$" />/ 
26   </form>  
27  </body>
28 </html>

第一个应为   re=new RegExp("^\\d*$");     

\在引号中需要转义,第一个有双引号,双引号要加多一次转义的,第二个没有,这就是区别