js如何获取左侧第一个空格?
如何或者左侧第一空格,并且删除这个空格左侧的所有字符?
比如:var str1 = "12 34dfasndwq312312 "; var str2 = "1 dsa45378dqe12 ";
希望能够删除“12 ”和 “1 ”,得到“34dfasndwq312312”和“dsa45378dqe12”
------解决方案-------------------- <script language=javascript>
var str1 = "12 34dfasndwq312312 ";
re=/^[^\s]+\s+/
str1=str1.replace(re, " ")
alert(str1)
</script>
------解决方案--------------------var str1 = "12 34dfasndw q312312 ";
var str2 = "1 dsa45378dqe12 ";
var exag = /([A-Za-z0-9_]+)[ ](.*)/;
alert(str1.replace(exag, "$2 "));
------解决方案--------------------function aaa(str){
var myArray = new Array();
myArray=str1.split( " ");
alert(myArray[1]);
}
aaa(str1);
这个如何?
------解决方案--------------------你这前后的描述不一致阿。按第一个描述。
function aaa(str){
var myArray = new Array();
myArray=str.split( " ");
alert(myArray.slice(1));
}
aaa( "1 dsa45378dqe12 ");
------解决方案-------------------- <script type= "text/javascript ">
var str= "8sadasdas ";
var ary=str.split( " ");
for(var i=0;i <ary.length;i++)
{
if(!isNaN(ary[i]))
{
ary.splice(i,1);
}
}
alert(ary.join( " "));
</script>