其他分享
首页 > 其他分享> > 运用正则表达式去左右空格

运用正则表达式去左右空格

作者:互联网

var oBtn = document.getElementById(“btn”);
var oTxt = document.getElementById(“txt”);
oBtn.onclick = function(){
var str = oTxt.value;
//var re = /^\s+/g;
//var re = /\s+KaTeX parse error: Expected group after '^' at position 20: … var re = /(^̲\s+|\s+)/g;
str = str.replace(re,’’);
alert(’-’ + str + ‘-’)
}

标签:oBtn,正则表达式,oTxt,空格,re,str,var,运用,document
来源: https://blog.csdn.net/weixin_45052104/article/details/90896385