Just make sure you use something like `/(?:^{\s*)|(?:\s*}$)/` instead of the regex in the second comment.