-
<script language="javascript"> function check() { var str=document.getElementById("input1").value var s="^正则表达式$" var re = new RegExp(s, "ig"); alert(re.test(str)) } </script> <input id="input1" value="正则表达式"> <input type="button" value="确定" onclick="check()"> ============================ <script language="javascript"> function check2() { var str2=document.getElementById("input2").value var s2="正则表达式" var re = eval("/^"+s2+"$/ig") alert(re.test(str2)) } </script> <input id="input2" value="正则表达式"> <input type="button" value="确定" onclick="check2()">