日期:2014-05-16  浏览次数:20323 次

js正则表达式中的/g和/i的含义

js正则表达式中的/g和/i的含义

  • g?? /global?? 代表全局搜索 ??
  • i?? /ignore?? 代表忽略大小写?
  • gi: 以上组合?

例子:?
var   str   =   "AAbbAAbAAAbAAAA";   
str   =   str.replace(/b/,"*");   // AA*bAAbAAAbAAAA 
alert("没使用全局g结果   --   "   +   str);   
str   =   str.replace(/b/g,"*");   // AA**AA*AAA*AAAA 
alert("使用了全局g结果   --   "   +   str);   
?