Parser replace pattern <p>I have problems with pattern. I need to process some text for example:</p> <pre><code>&lt;div&gt;{text1}&lt;/div&gt;&lt;span&gt;{text2}&lt;/span&gt; </code></pre> <p>After the process I need to get in place of {text1} and {text2} some words from dictionary. I'm preparing ui interface for diffrent languages. This is in PHP. For now I have something like this but this doesn't work:</p> <pre><code>function translate_callback($matches) { global $dict; print_r($matches); return 'replacement'; } function translate($input) { return preg_replace_callback('/(\{.+\})/', 'translate_callback', $input); } echo translate('&lt;div&gt;{bodynum}&lt;/div&gt;&lt;span&gt;{innernum}&lt;/span&gt;'); </code></pre> <p>This is test scenarion but I can't find the way to define pattern because this one in code match</p> <pre><code>{bodynum}&lt;/div&gt;&lt;span&gt;{innernum} </code></pre> <p>but I want pattern that will match</p> <pre><code>{bodynum} and then {innernum} </code></pre> <p>Can somebody help me with this. Thanks.</p> <p>The Solution:</p> <p>To match any character between { and }, but don't be greedy - match the shortest string which ends with } (the ? stops + being greedy).</p> <p>So the pattern now looks like: '/{(.+?)}/' and is exacly what I want.</p>