比如有字符串:
str = '12+56-(47+12)*2 ';
如何取将里面的数字及运算符分别提出并存至数组中?
想要的结果为:
arr1[0]=12
arr1[1]=56
arr1[2]=47
arr1[3]=12
arr1[4]=2
---
arr2[0]= "+ ";
arr2[1]= "-( ";
arr2[2]= "+ ";
arr2[3]= ")* ";
------解决方案--------------------
<script type= "text/javascript ">
var str = '12+56-(47+12)*2 '
alert(str.replace(/(\d)+/g, " ").replace(/^ *(.*?) *$/, "$1 ").split( " "))
alert(str.match(/(\d)+/g))
</script>
------解决方案--------------------
alert(str.match(/(\d)+/g))
alert(str.match(/(\D)+/g))