Abk - 1 year ago 94

Javascript Question

I have the following variables

`var arithmetic = "96-66.33+99.3/22*58.2";`

var arr;

var operator = "/*+-^";

I want to

`arithmetic`

`index`

`operator`

`index`

`operator`

The final result will be

`["96-66.33", "+99.3", "/22", "*58.2"];`

`var arithmetic = "96-66.33+99.3/22*58.2";`

arithmetic = arithmetic.split(/(?=[-+*\/])/);

console.log(arithmetic);

The

`arithmetic`

The

`arithmetic`

If I can still get result to be

`["96", "-66.33", "+99.3", "/22", "*58.2"];`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Closest I could get you through regexp. Very close but not it exactly yet.

```
var arithmetic = "96-66.33+99.3/22*58.2";
arithmetic = arithmetic.split(/([-+*\/])/g);
console.log(arithmetic);
```

EDIT: Got it.

```
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);
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**