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

JS 利用正则表达式替换字符串
JS 利用正则表达式替换字符串
var data = "123123,213,12312,312,3,Caat,cat,dsfsdfs,";
var reCat = /\bc([a-z]|[A-Z]|[0-9])*t\b/ig;  //?g(全文查找);?i(忽略大小写);?m(多行查找)
var res = data.replace(reCat,"AAA");
输出:123123,213,12312,312,3,AAA,AAA,dsfsdfs,

var data = "src=\"http://img6.nanhao360.com/p11/20130812/962-b82c-2b.jpg\" height=";
var reCat = /\bhttp:\/\/([a-z]|[A-Z]|[0-9]|\/|\.|-)*\.([jpg]|[png]|[gif])+\b/ig;
var res = data.replace(reCat,"AAA");
输出:src="AAA" height=