It's quite hard to explain this using words, so perhaps I can just show what I'm wanting.
Currently I have the following code:
const regex = /(\d?\s\+?\s\d)|(\d?\s\-?\s\d)/g
const match = '1 + 2 - 7'.match(regex)
console.log(match)
This returns two matches:
[ "1 + 2", " - 7" ]
Now, what I want to know, is it possible to create a regex pattern that can match the integer 2
twice and make it part of two results?
Desired output:
[ "1 + 2", "2 - 7" ]