字符串处理

replace

str.replace(/</?[^>]*>/g,''); //去除HTML tag,g代表去除所有

str.replace(/[ | ]* /g,' '); //去除行尾空白

str.replace(/ [s| | ]* /g,' '); //去除多余空行

str.replace(/ /ig,'');//去掉

str.replace(/^[s ]+|[s ]+$/g, "");//去掉全角半角空格

str.replace(/[ ]/g,"");//去掉回车换行

str.replace(/(^/s*)|(/s*$)/g, ""); // 去掉左右空格

str.replace(/(^/s*)/g, ""); // 去掉左空格

str.replace(/(/s*$)/g, ""); // 去掉右空格

join

arr=["1","1","1","1"];

str=arr.join(",");    //str=1,1,1,1

split

str="1,1,1,1";

arr=str.split(",");    //["1","1","1","1"];

原文地址:https://www.cnblogs.com/sweetyu/p/5310534.html