regexp靜態(tài)的實(shí)例屬性

字號(hào):


    靜態(tài)的regexp屬性對(duì)說(shuō)有的正則表達(dá)式都有效,這些屬性頁(yè)與眾不同。因?yàn)樗鼈兌加袃蓚€(gè)名字,一個(gè)復(fù)雜的名字和一個(gè)以美元符號(hào)開(kāi)頭的尖端名字,下面就是那些屬性。
    長(zhǎng)名 短名 描述
    inptu $_ 最后用于匹配的字符串(傳遞個(gè)exec()或者test()的字符串)
    lastmatch $& 最后匹配的字符
    lastparen $+ 最后匹配的分組
    leftcontent $\(\是個(gè)下滑點(diǎn),打不出來(lái)用\代替) 上次匹配的前面的字串
    multiline $* 用于指定是否所有的表達(dá)式使用多行模式的布爾值
    rightcontent $' 在上次匹配之后的字串
    舉例說(shuō)明
    var str = this site is 3w forasp cn;
    var re = /(3w)forasp/gi;
    re.test(str);
    alert(regexp.input);//輸出this site is forasp cn
    alert(regexp.leftcontext);//輸出this site is
    alert(regexp.rightcontext);//輸出cn
    alert(regexp.lastmatch);//輸出forasp
    alert(regexp.lastparen);//輸出3w
    如果用簡(jiǎn)單方式替換
    regexp[簡(jiǎn)單模式]
    這個(gè)靜態(tài)屬性基本不常用,也不在此多說(shuō)了