//正则表达式主要用来验证客户端的输入数据
//创建正则表达式有两种创建的方法:1、new运算符 2、采用字面量
//正则表达式 (regular expression)是一个描述字符模式的对象。
// i 不区分大小写
//RegExp 对象包含两个方法:
//test()和 exec(),功能基本相似,
//test()用于测试字符串匹配法在字符串中查找是否存在指定的正则表达式并返回布尔值,如果存在则返回 在则返回 false
//exec()方法也用于在字符串中查找指定正则表达式,如果 exec(功,则返回包含该查找字符串的相关信息数组。如果执行失败,则返回 nul
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>正则表达式03</title>
</head>
<body>
<!-- 例1、-->
<!-- <p>1.替换 "Microsoft" 为 "W3cSchool" :</p> -->
<!-- <button οnclick="myFunction()">点我</button> -->
<!-- <p id="demo">请访问 Microsoft!</p> -->
<script type="text/javascript" language="javascript">
//例1、
//replace() 方法使用正则表达式
//将替换 "Microsoft" 为 "W3cSchool"
<!-- function myFunction() { -->
<!-- var str = document.getElementById("demo").innerHTML; -->
<!-- var txt = str.replace("Microsoft","W3cSchool"); -->
<!-- document.getElementById("demo").innerHTML = txt; -->
<!-- } -->
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
// 例2、
//使用 split 拆分成字符串
//var str="How are you doing today?"
//document.write(str.split(" ") + "<br />"); // How,are,you,doing,today?
//document.write(str.split("") + "<br />"); // H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
//document.write(str.split(" ",3) + "<br/>"); // How,are,you
</script>