Interpolating code delimited with character that can appear in code
I see an extra unnecessary variable that you can get rid of, or change another variable so that it makes more sense.

int opening = i;


you use this inside of a for loop.  You can do 2 things with this.


Just use the variable i where ever you had the variable opening
change the i variable to opening in the for loop like 

for (int opening = 0; opening &lt; str.Length; opening++)



hopefully this shows you how unnecessary that extra variable is, it isn't used anywhere else for anything other than the loops. 



Other than that I would need to play with it and spend some time with it to see if it plays well with others.