Example
preg_replace('/\{[a-zA-Z.,\(\)0-9]+\}/', 'Replaced', 'Lorem ipsum dolor sit {tag1({tag2()})}, consectetur adipiscing elit.');
The result:
Lorem ipsum dolor sit {tag1(Replaced)}, consectetur adipiscing elit.
Question
As you can see “tag2” has been replaced, But I want to replace “tag1”
Do anyone know how I can do this?
(In some cases it might be like this:{tag1({tag2({tag3()})})}) and so on.)
Btw I am actually using preg_replace_callback, but its easier to show it with preg_replace
Here is a site where you can test the code: http://www.spaweditor.com/scripts/regex/index.php
You need to add curly braces to your character set. Here’s the pattern I used:
And here was the result: