This is really quite simple. You're using preg_match, which attempts to find one occurance of a given pattern, to find all matches use preg_match_all.
Both work in the same way: the $matches array will have the full pattern-match assigned to index 0 (including the quotes), and the group(s) will be assigned to all subsequent indexes (in this case $matches[0] will contain the chars inside the quotes). The difference is that preg_match_all will assign arrays to the aforementioned indexes, listing each match for the pattern.
preg_match("/'([^]+)'/", $input, $matches);
var_dump($matches);
will give an array like this:
array(
"'wonderful'", //because the pattern mentions the ' chars
"wonderful" //because I'm grouping the chars inside the '
);
Whereas this code:
preg_match_all("/'([^']+)'/", $input, $matches));
Gives you:
array (
//array of full matches, including the quotes
array (
'\'wonderful\'',
'\'stuck\'',
),
//array with groups
array (
'wonderful',
'stuck',
),
);
As you can see on this live example
I've simplified your expression a little, because you're interested in what's "delimited" by single quotes, hence I match and group every non ' that follows a single quote and that is, in turn followed by another single quote. Thus, the char-class you want to match is simply [^']... anything except '.
A possiple micro-optimization you could make to this suggested pattern would be to use a possessive quantifier ++, which is similar to {1,}. Or, if you want to match an empty string if '' is found, you could use *+. so
if (preg_match_all("/'([^']++)'/", $subject, $matches))
var_dump($matches);
Should do the trick
~\'(.*?)\'~gand remove the last ')' which I guess was a typo (or it wouldn't have worked at all). (Also, escaping the ' aren't necessary.)preg_match_allfunction which does the same thing