文本匹配提取URL链接
var targetText = '教书先生博客:blog.oioweb.cn';
var re = /((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/gi;
// 使用全局匹配:
var matches = targetText.match(re);
document.write(matches);
过滤文本行所有换行
var str = "教书先生博客\nblog.oioweb.cn";
var getArr = str.split("\n");
var strreverse = "";
for (var i = 0; i < getArr.length; i++) {
strreverse = strreverse + getArr[i].replace(/[\r\n]/g, "");
}
console.log(strreverse);
去掉文本中所有空格
var str = " Wel come\n" +
"Wel come\n" +
" 教书先生";
var getArr = str.split("\n");
var strreverse = "";
for (var i = 0; i < getArr.length; i++) {
strreverse = strreverse + getArr[i].replace(/[ ]/g, "") + "\n";
}
console.log(strreverse);