PHP Programming
preg_match() not returning all subpatterns... - http://www.reddit.com/r...
I've been playing around with this code for far too long now and can't figure out why it's not working correctly. I'm trying to pull out the information from a specific code syntax using a regular expression: $line = "[%condition:'a':{option 1},'b':{option 2},'c':{option 3}%]"; if(preg_match('/\[%condition:(?:\'([^\']+)\':{([^}]*)},)*\'([^\']+)\':{([^}]*)}%\]/', $line, $matches)){ print 'matched'; print_r($matches); } else { print 'no match'; } Essentially, I'm trying to get each condition in between the single quotes, and then each option between the curly braces. There can be any number of conditions in the list. When I run this, it matches $line as expected, but the contents of $matches are as follows: matched Array ( [0] => [%condition:'a':{option 1},'b':{option 2},'c':{option 3}%] [1] => b [2] => option 2 [3] => c [4] => option 3 ) As you can see, it skips right over 'a':{option 1}. When I tried putting in a fourth item in the list, it only pulled the last two. What's going on,...