正则表达式 multiline 属性

返回 Boolean 值,指出正则表达式使用的 multiline 标志(m)的状态。默认值为 false。只读。

rgExp.multiline

必选项 rgExp 参数为 RegExp 对象。

说明

如果正则表达式设置了 multiline 标志,那么 multiline 属性返回 true,否则返回 false。如果创建正则表达式对象时使用了 m 标志,那么 multiline 属性就是 true

如果 multilinefalse,那么 "^" 匹配字符串的开始位置,而 "$" 匹配字符串的结束位置。如果 multlinetrue,那么 "^" 匹配字符串开始位置以及 "/n" 或 "/r" 之后的位置,而 "$" 匹配字符串结束位置以及 "/n" 或 "/r" 之前的位置。

示例

以下示例演示了 multiline 属性的特征。如果将 "m" 传递给下面所示的函数,单词 "while" 将被替换为 "and"。这是因为设置了 multiline 标志且 "while" 出现在换行字符的下一行的开始位置。multiline 标志允许在多行的字符串中进行查找。

本函数返回一个字符串以及一个表,表中显示了允许使用的正则表达式标志(gim)的状态。它还返回经过所有替换操作的字符串。

function RegExpPropDemo(flag){
   if (flag.match(/[^gim]/))          //检查标志的有效性。
     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 标志。
     s += " True     ";
   else
     s += "False     ";
   if (re.ignoreCase)                 //测试 ignoreCase 标志。
     s += " True  ";
   else
     s += "False  ";
   if (re.multiline)                  //测试 multiline 标志。
     s += "     True     ";
   else
     s += "     False   ";
   s += "/n/nThe resulting string is:/n/n" + r;
   return(s);                         //返回替换的字符串。
}
要求

版本 5.5

请参阅

global 属性 | ignoreCase 属性 | 正则表达式语法

应用于:RegExp 对象

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值