bluebyyou Posted February 17, 2010 Share Posted February 17, 2010 <?php $str = "Some {sample|example|variable} text. More {text|things|stuff} text."; $pattern ="/\{.*\}/is"; preg_match_all($pattern, $str, $matches); foreach ($matches as $val) { print_r($val); } ?> It outputs: Array ( [0] => {sample|example|variable} text. More {text|things|stuff} ) ------------- What I want the output to be is each string between the {}'s to be parsed out individually, I just am having a hell of a time writing the proper regular expression. Can someone point me in the right direction? Quote Link to comment Share on other sites More sharing options...
cags Posted February 17, 2010 Share Posted February 17, 2010 It's because by default .* is a greedy search, meaning it will keep matching whilst it can. You could make the search lazy by adding a question mark after the .* match. Personally thought I'd opt to use [^}]* as your match instead. '#\{[^}]*\}#s' Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted February 17, 2010 Author Share Posted February 17, 2010 Thanks, that did the trick! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.