I can replace ABC(10,5) with (10)%(5) using:
replaceAll("ABC\\(([^,]*)\\,([^,]*)\\)", "($1)%($2)")
but I’m unable to figure out how to do it for ABC(ABC(20,2),5) or ABC(ABC(30,2),3+2).
If I’m able to convert to ((20)%(2))%5 how can I convert back to ABC(ABC(20,2),5)?
Thanks,
j
I am going to answer about the first question. I was not able to do the task in a single
replaceAll. I don’t think it is even achievable. However if I use loop then this should do the work for you:I am assuming you are writing parser for numeric expressions, thus the definition of term
termString = "([0-9+\\-*/()%]*)". It outputs this:EDIT As per the OP request I add the code for decoding the strings. It is a bit more hacky than the forward scenario:
And the output is: