?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
JScript? | 語言參考 |
返回 Boolean 值,指出正則表達(dá)式使用的 multiline 標(biāo)志(m)的狀態(tài)。默認(rèn)值為 false。只讀。
rgExp.multiline
必選項(xiàng) rgExp 參數(shù)為 RegExp 對象。
如果正則表達(dá)式設(shè)置了 multiline 標(biāo)志,那么 multiline 屬性返回 true,否則返回 false。如果創(chuàng)建正則表達(dá)式對象時(shí)使用了 m 標(biāo)志,那么 multiline 屬性就是 true。
如果 multiline 為 false,那么 "^" 匹配字符串的開始位置,而 "$" 匹配字符串的結(jié)束位置。如果 multline 為 true,那么 "^" 匹配字符串開始位置以及 "\n" 或 "\r" 之后的位置,而 "$" 匹配字符串結(jié)束位置以及 "\n" 或 "\r" 之前的位置。
以下示例演示了 multiline 屬性的特征。如果將 "m" 傳遞給下面所示的函數(shù),單詞 "while" 將被替換為 "and"。這是因?yàn)樵O(shè)置了 multiline 標(biāo)志且 "while" 出現(xiàn)在換行字符的下一行的開始位置。multiline 標(biāo)志允許在多行的字符串中進(jìn)行查找。
本函數(shù)返回一個(gè)字符串以及一個(gè)表,表中顯示了允許使用的正則表達(dá)式標(biāo)志(g、i 和 m)的狀態(tài)。它還返回經(jīng)過所有替換操作的字符串。
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.";
ss += "\nwhile the fielder caught the ball with the glove.";
re = new RegExp("^while",flag); //
指定要查找的樣式。r = ss.replace(re, "and"); //
用"a"
替換"the"
。s = "Regular Expression property values:\n\n"
s += "global ignoreCase multiline\n"
if (re.global) //
測試global
標(biāo)志。s += " True ";
else
s += "False ";
if (re.ignoreCase) //
測試ignoreCase
標(biāo)志。s += " True ";
else
s += "False ";
if (re.multiline) //
測試multiline
標(biāo)志。s += " True ";
else
s += " False ";
s += "\n\nThe resulting string is:\n\n" + r;
return(s); //
返回替換的字符串。 }
版本 5.5
global 屬性 | ignoreCase 屬性 | 正則表達(dá)式語法
應(yīng)用于:RegExp 對象