Here I accept it.
$string = '"a-b""c-d""e-f"';
if ( preg_match_all( '/"(.*?)"/', $string, $matches ) )
{
print_r( $matches[1] );
}
And a breakdown of the template
" // match a double quote
( // start a capture group
. // match any character
* // zero or more times
? // but do so in an ungreedy fashion
) // close the captured group
" // match a double quote
The reason you are looking $matches[1], and not $matches[0], is that it preg_match_all()returns each captured group to indices 1-9, while all pattern matches have index 0. Since we only need content in the capture (in this case, the first capture group), we are looking at $matches[1].
source
share