tags:

views:

47

answers:

1

Exsample

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 whant 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 iam actually using preg_replace_callback, but its easyer to show it with preg_replace

Here is a site where you can test the code: http://www.spaweditor.com/scripts/regex/index.php

+1  A: 

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."
Ender
Tanks!, it works :) Iam almost there now i think.Do you know a pattern to replace everything except something.something in the result i got: {something.something({print.print(param1,param2)},param2)}something.something can be: [a-zA-Z.]
christian