var pattern=/<(\w+)(>)/g;
var se=pattern.exec(str);
var se1=pattern.exec(str);
console.log(se)//[ "<tt>","tt" ,">"]数组第一项是匹配项,第二项代表第一个捕获项
console.log(se1)[ "<rr>","rr",">" ]数组第一项是匹配项,第二项代表第一个捕获项,第三项代表第二个捕获项
var str='<tt><rr><rr/><ll><lt></lt><ll/><dd></dd><rr/><tt><tt/><rr><rr/>';
var ss=str.match(/<\w+>/); [ "<tt>" ]
var sss=str.match(/<\w+>/g); rr>","<ll>","<lt>","<dd>","<tt>","<rr>" ]
var sea=str.search(/<\w+>/); 0
var sea1=str.search(/<\w+\/>/);8
var text="cat bat ut dat"var re=text.replace("at","11");c11 bat ut dat
var re1=text.replace(/at/g,1)">c11 b11 ut d11
var re2=text.replace(/(.a(t))/g,"$1$2") ;catt batt ut datt
function replaceText(text){
return text.replace(/at/g,(match,pos,originalText){
console.log(match+" "+pos+" "+originalText);要输出三次
})
}
replaceText(text);
at 1 cat bat ut dat
at 5 cat bat ut dat
at 12 cat bat ut dat
最终结果是cundefined bundefined ut dundefined
因为函数没有返回值,所以是undefined
var result=text.split(/\s/);[ "cat","bat","ut","dat" ]
var result1=text.split(/\s/,2);