我有以下变量
var arithmetic = "96-66.33+99.3/22*58.2";
var arr;
var operator = "/*+-^";
我想分裂的arithmetic
每发生或index
的operator
变量。
最终结果将是 ["96", "-66.33", "+99.3", "/22", "*58.2"];
V.Roudge提供的最终解决方案
var arithmetic = "96-66.33+99.3/22*58.2";
arithmetic = arithmetic.split(/(?=[-+*\/])/);
console.log(arithmetic);
最近,我可以让您通过正则表达式。非常接近,但还不完全正确。
var arithmetic = "96-66.33+99.3/22*58.2";
arithmetic = arithmetic.split(/([-+*\/])/g);
console.log(arithmetic);
编辑:知道了。
var arithmetic = "96-66.33+99.3/22*58.2";
arithmetic = arithmetic.split(/(?=[-+*\/])/);
console.log(arithmetic);
var arithmetic = "96-66.33+99.3/22*58.2";
arithmetic = arithmetic.split(/(?=[-+*\/])/);
console.log(arithmetic);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句