I'm trying to split math expressions using regex although no matter what I try, there's always one condition that I'm missing.
I need to split the string on all operators +,-,*,/
and on all types of brackets (,),[,]
. If there's an increment or decrement ++,--
I need to keep it as one string. I also have to keep multidigit numbers as one string.
Right now, the closest thing I have is:
(?<![+-[0-9]])(?=[*/+-\[\]\(\)])|(?<=[*/+-\[\]\(\)])(?![+-[0-9]])
For example, [(([++[[(--2)]*33]])/22)+1]
should give
[,(,(,[,++,[,[,(,--,2,),],*,33,],],),/,22,),+,1,]
but instead gives
[,(,(,[,++,[,[,(,
--2,),],*,33,],],),/,22,),
+1,]