I have the following regex that matches correctly in https://regex101.com but not when using preg_replace_callback in PHP.
(?<!\\)(?:\\\\)*{(.*?)(:(.*?))?}
It works mostly but it doesn't seem to work for multiple levels of escapes. Example text processing (bold matches correctly, italic shows what should be matching and isn't or what is matching and shouldn't):
{intro} The quick brown {animal} jumped over the lazy {otherAnimal}. Empty {} should also match. Escaped should \{not match}. Escaped escape before \\{should match}. 3 escapes should \\\{not match}. 4 escapes \\\\{should match}.
Note that in PHP, the exact code is this with the doubled slashes since it's in a PHP string:
preg_replace_callback('/(?<!\\\\)(?:\\\\\\\\)*{(.*?)(:(.*?))?}/',...