...

/

Solution: Adjust the Pattern To Return the Required Matches

Solution: Adjust the Pattern To Return the Required Matches

Learn how to adjust the pattern that will return the required output.

We'll cover the following...

Problem statement

Observe following code sample:

Press + to interact
<?php
$text = <<<'TEXT'
"one", "two", "three, \"four\", five", "six", "seven"
TEXT;
preg_match_all(
'/".*?"/',
$text,
$matches
);

This will return the following matches:

[
  0 => [
    0 => ""one""
    1 => ""two""
    2 => ""three, \""
    3 =>
...