fix($interpolate): use the first end symbol that forms a valid expression

When an interpolation string has multiple end symbol choices, pick the
occurrence that forms a valid expression

Closes #8642
As I said, that's just a suggestion for a direction to get rid of this pretty cryptic switch statement, I didn't really test it. Anyway, I modified it a bit so it will work with the failure you mentioned.