I need to split a string that looks like "12+3-4=" into an array that looks like ["12", "+", "3", "-", "4", "="]
The regex I used works in Chrome, but not in Safari and after doing google search I realized that Safari doesn't yet support lookbehinds. Is there another way to write the following regex so that it does the above, but works in Safari too?
const arr = displayValue.split(/(?=[\-\+\/\*\=])|(?<=[\-\+\/\*\=])/)
Try using match
with an alternation:
var input = "12+3-4=";
var parts = input.match(/\d+|[*/=+-]/g);
console.log(parts);