math is hard - check the bounds of a string properly when looking to see if a closing } exists