<!DOCTYPE html PUBLIC "-//W 3C//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> <title>Untitled Page</title> <script language="jscript" type="text/jscript">... function SplitDemo()...{ var s, ss; var s ="The rain in Spain falls mainly in the plain."; // 在每个空格字符处进行分解。 re =/ain/i ss = s.split(re); return(ss); } function MatchDemo()...{ var r, re; // 声明变量。 var s ="The rain in Spain falls mainly in the plain"; re =/In/i; // 创建正则表达式模式。 r = s.match(re); // 尝试匹配搜索字符串。 return(r); // 返回第一次出现"ain" 的地方。 } function ReplaceDemo()...{ var r, re; // 声明变量。 var ss ="The rain in Spain falls mainly in the plain."; re =/(S+)(s+)(S+)/g; // 创建正则表达式模式。 r = ss.replace(re, "$3$2$1"); // 交换每一对单词。 return(r); // 返回结果字符串。 } function matchDemo()...{ var re =/<.*?>/; var str ="<h1>asdasdasdasdasd</h1>"; var arr = re.exec(str); s ="$1 contains: "+ RegExp.$1+""; s +="$2 contains: "+ RegExp.$2+""; s +="$3 contains: "+ RegExp.$3; return(arr); } </script> </head> <body onload="alert(matchDemo())"> </body> </html>
DOCTYPE html PUBLIC "-//W 3C//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> title>Untitled Pagetitle>