You are using non-greedy quantifiers (the "
[^~]+?" part). As
the manual states, that is not supported. Use the "Minimal matching" option. In time, the current regex engine will be replaced with PCRE which supports such constructs.
I really do suggest that people read the manual.