Regular Expression just one step away from what I need....

From: Date: Fri, 17 Aug 2007 17:00:46 +0000
Subject: Regular Expression just one step away from what I need....
Groups: php.general php.general 
Request: Send a blank email to php-general+get-260971@lists.php.net to get a copy of this message
Given the string 'foo''bar''glorp' (all quotes are single quotes)I had hoped to find a regular expression using preg_match that would return an array containing just those words without having to go through additional gyrations, like exploding a string to get an array. I have only had limited luck $theString = "'foo''bar''glorp'"; preg_match( "/\'(.*)\'/", $theString, $matches); print_r($matches); Array ( [0] => 'foo''bar''glorp' [1] => foo''bar''glorp ) Of course $matches[0] has the entire string and $matches[1] contains the returned string minus the leading and trailing single quote. I can explode $matches[1] to get what I want, but it is an extra step and I am sure that I have done this before but cannot locate the code in question. I would like the results to be Array ( [0] => 'foo''bar''glorp' [1] => foo [2] => bar [3] => glorp ) That way I can use the $matches array without having to create another array to hold the values. I feel as if I am really close on the regex to do this, but cannot seem to find (after much head scratching and teeth gnashing) the proper solution. Much thanks!

« previous php.general (#260971) next »