I suggest writing a simple parser / tokenizer for this.
Basically, you iterate over all characters and start counting instances of { and } - increase for { and decrease for } . Write down the index of each first { and the index of each last } , and you will have indexes for the built-in expressions.
At this point, you can use substring to get them and remove / replace from the original string.
See this question and answers why RegEx is not suitable.
Odded
source share