Using preg_replace with variable to get database record
===

I am looking for a solution where I can use preg_replace to replace certain strings in a body of text where some of the strings may contain a variable which will then call upon a database to retrieve the replacement value (or a function which retrieves that value).

For example, I may want to replace the following strings as follows - the one in *italics* is the one I am struggling with:

<code>{today} => today's date

{title} => document title

*{lang:12} => from "lang" table in database where id=12*</code>

The first two are easy, obviously, but I am struggling with the third. The only thing I can think of is to do the replacements of all those that don't have a colon and then any which do have a colon, to trigger a function.