javascript--正则

  • 字符串去除空格

去除所有空格

var txt=document.getElementById('txt').value;
txt=txt.replace(/\s+/g,"");

去除两头空格

var txt=document.getElementById('txt').value;
txt=txt.replace(/^\s+|\s+$/g,"");

去除左边空格

var txt=document.getElementById('txt').value;
txt=txt.replace(/^\s*/g,"");

去除右边空格

var txt=document.getElementById('txt').value;
txt=txt.replace(/(\s*$)/g,"");

获取注释中的一行

function hereDoc(f) {return f.toString().replace(/^[^\/]+\/\*!?\s?/, '').replace(/\*\/[^\/]+$/, '');}

 

posted @ 2020-03-18 01:43  sjzhen  阅读(60)  评论(0编辑  收藏  举报