JS 利用正则表达式替换字符串博客分类: JavaScript学习资料 Java代码 收藏代码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=