欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript compile() 方法

定義和用法

compile() 方法用于在腳本執(zhí)行過程中編譯正則表達(dá)式。

compile() 方法也可用于改變和重新編譯正則表達(dá)式。

語法

RegExpObject.compile(regexp,modifier)
參數(shù) 描述
regexp 正則表達(dá)式。
modifier 規(guī)定匹配的類型。"g" 用于全局匹配,"i" 用于區(qū)分大小寫,"gi" 用于全局區(qū)分大小寫的匹配。

實(shí)例

在字符串中全局搜索 "man",并用 "person" 替換。然后通過 compile() 方法,改變正則表達(dá)式,用 "person" 替換 "man" 或 "woman",:

<script type="text/javascript">

var str="Every man in the world! Every woman on earth!";

patt=/man/g;
str2=str.replace(patt,"person");
document.write(str2+"<br />");

patt=/(wo)?man/g;
patt.compile(patt);
str2=str.replace(patt,"person");
document.write(str2);

</script>

輸出:

Every person in the world! Every woperson on earth!
Every person in the world! Every person on earth!

TIY

TIY

compile()
如何使用 compile() 來改變正則表達(dá)式。