« first day (2143 days earlier)      last day (1649 days later) » 

 
8 hours later…
 
8 hours later…
5:54 PM
Imagine I have an string like this: 10*((4+9)-(5-1)) and I want to make a recursive function able calculate this step by step, so, the first thing I must do is to capture and calculate all the operations in brackets.
In order to capture, I can either capture first ((4+9)-(5-1)), and recursively capture (4+9) and (5-1) to calculate them, then with the result calculate the grater bracket. Or capture (4+9) and (5-1), calculate them and then capture the result (13-4) to finally calculate it.
The problem is, that in either of them I don't know which regex use. I was trying to do \((.*)\) but it captures all the brackets as if they were only one, so, e.g: 4+(5+6)-(3*2) is captured as (5+6)-(3*2) using the outer brackets, which is wrong.
Any idea?
Note, my real problem isn't about a normal calculator
 

« first day (2143 days earlier)      last day (1649 days later) »