名称 支持正则 特 点 备注 str_replace X 字符串替换函数,大小写敏感 str_ireplace X 字符串替换函数,大小写不敏感,支持数组式批量替换 感谢网友franci, 提醒添加 substr_replace X 部分替换字符串函数,可以指定位置index preg_replace Y 指定匹配 模式进行替换,支持子串引用 优先使用 ereg_replace Y 指定匹配 模式进行替换,大小写敏感,支持子串引用 eregi_replace Y 指
特殊字符匹配 var pattern=/\[/; // 用\符号来转义正则里的特殊字符才能匹配 var str='['; alert(pattern.test(str)); 换行模式 var pattern=/\d+/g; // 未限定首匹配 var str='1.baidu\n2.google\n3.bing'; alert(str.replace(pattern,'#')); var pattern=/^\d+/gm; // 限定首匹配,并且开启换行模式 var str='1.baidu\n