Example
preg_replace(\'/\\{[a-zA-Z.,\\(\\)0-9]+\\}/\', \'Replaced\', \'Lorem ipsum dolor sit {tag1({tag2()})}, consectetur adipiscing elit.\');
You might want to use T-Regx:
<?php
$subject = 'Lorem ipsum dolor sit {tag1({tag2()})}, consectetur adipiscing elit.';
pattern('\{[a-zA-Z.,()0-9]+\}')->replace($subject)->first()->with('Replaced');
You need to add curly braces to your character set. Here's the pattern I used:
/\{[a-zA-Z.,\(\)\{\}0-9]+\}/
And here was the result:
"Lorem ipsum dolor sit Replaced, consectetur adipiscing elit."
Once you start talking about matching nested patterns (eg: matching the inner bracketed group in something like (foo (bar) fu)
), then regex is the wrong tool. Regular Expressions are stateless, which, in this case, means that they can't count how many brackets are open.
If you are looking to do something like that, you might need to look into a parser