在php中解析模板字符串

I am having an issue with string parsing in php. I am trying to create my own template parser (for my learning purpose). I have decided to put urls in the following format {url:abc/def} so this would be displayed like http://www.domain.com/abc/def. I have tried using str_replace but in this case it would not work since the value after ":" could be anything. Exploding the string also wont work as ":" can also be present in the text of html file. I think this could be only done via regular expression so suggest me some good regular expression also do let me know if this can be achieved via any other approach.

Other things to note.

  1. Since it is used for template parsing and template can have multiple urls.
  2. Urls would not have any query strings but i would appreciate if the solution also supports them.

for learning purposes then:

preg_replace('/\{url:([^\}]*)\}/', $base_url.'$1', $string);

And the explanation of the regex

  1. \{url: <-- find this text
  2. [^\}]* <-- this means 'any character but a } occuring 0 or more times
  3. ([^\}]*) <-- by putting it inbetween () we can later reference it (see the '$1')
  4. \} <-- the closing }

As long as you're learning: take a look at http://www.regular-expressions.info/ for more info on regular expressions. They're quite awesome really :D