?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
JScript? | 語(yǔ)言參考 |
返回 Boolean 值,指出正則表達(dá)式使用的 ignoreCase 標(biāo)志(i) 的狀態(tài)。默認(rèn)值為 false。只讀。
rgExp.ignoreCase
必選項(xiàng) rgExp 參數(shù)為 RegExp 對(duì)象。
如果正則表達(dá)式設(shè)置了 ignoreCase 標(biāo)志,那么 ignoreCase 屬性返回 true,否則返回 false。
如果使用了 ignoreCase 標(biāo)志,那就表明在被查找的字符串中匹配樣式的時(shí)候查找操作將不區(qū)分大小寫(xiě)。
以下示例演示了 ignoreCase 屬性的用法。如果傳遞 "i" 到下面所示的函數(shù)中,那么所有的單詞 "the" 將被 "a" 替換,包括最開(kāi)始位置上的 "The"。這是因?yàn)樵O(shè)置了 ignoreCase 標(biāo)志,搜索操作將不區(qū)分大小寫(xiě)。所以在進(jìn)行匹配的時(shí)候 "T" 與 "t" 是等價(jià)的。
此函數(shù)返回一個(gè)字符串以及一個(gè)表,表中顯示了與允許使用的正則表達(dá)式標(biāo)志(g、i 和 m)相關(guān)的屬性值。它還返回經(jīng)過(guò)所有替換操作后的字符串。
function RegExpPropDemo(flag){ if (flag.match(/[^gim]/)) //
檢查標(biāo)志的有效性。return("Flag specified is not valid");
var r, re, s //
聲明變量。var ss = "The man hit the ball with the bat.\n";
ss += "while the fielder caught the ball with the glove.";
re = new RegExp("the",flag); //
指定要查找的樣式。r = ss.replace(re, "a"); //
利用"a"
替換"the"
。s = "Regular Expression property values:\n\n"
s += "global ignoreCase multiline\n"
if (re.global) //
測(cè)試global
標(biāo)志。s += " True ";
else
s += "False ";
if (re.ignoreCase) //
測(cè)試ignoreCase
標(biāo)志。s += " True ";
else
s += "False ";
if (re.multiline) //
測(cè)試multiline
標(biāo)志。s += " True ";
else
s += " False ";
s += "\n\nThe resulting string is:\n\n" + r;
return(s); //
返回替換的字符串 }
版本 5.5
global 屬性 | multiline 屬性 | 正則表達(dá)式語(yǔ)法
應(yīng)用于:RegExp 對(duì)象