Deep (infinite) split words using regex
Lets say I have: $line = "{This is my {sentence|words} I wrote.}" Output: This is my sentence I wrote. This is my words I wrote. But, the regex should match deep and nested values and split these values, for example: $line = "{This is my {sentence|words} I wrote on a {sunny|cold} day.}"; Output: This is my sentence I wrote on a sunny day. This is my sentence I wrote on a cold day. This is my words I wrote on a sunny day. This is my words I wrote on a cold day. My first though was doing it over explode as in code below, but the result was not appropriate: $res = explode("|", $line); Advices?