How can I split a line: "-33 + 42", using regex, while preserving the delimiters? The separators are arithmetic signs, and their number can vary.

1 answer 1

\b(?<=\d|^)(?!$) 

It reads like this:
Word boundary \b
To the left of which is the number or the beginning of the line (?<=\d|^)
To the right of which is NOT the end of the line (?!$)

https://www.regex101.com/r/bH6lW6/8