Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only way I could get this to work is by using:</p> <pre><code>$subject = 'My 00123450 "Ralph" ("France" is my country, "123" my age, ... , "an other text", ...)'; $pattern = '/\((?:[^"\)]*"(.*?)")?(?:[^"\)]*"(.*?)")?(?:[^"\)]*"(.*?)")?[^"]*?\)/'; preg_match_all($pattern, $subject, $matches); for ($i = 1; $i &lt; count($matches); $i++) { print($i.': '.$matches[$i][0].";\n"); } </code></pre> <p><strong>Output:</strong></p> <pre><code>1: France; 2: 123; 3: an other text; </code></pre> <p>That Regex would only work for <em>up to</em> 3 occurrences of "quoted strings" inside a set of brackets. You could however extend the regex string to grab <em>up to</em> N occurrences as follows:</p> <p>The regex to find 1 to N quoted strings within each set of parenthesis is:</p> <pre><code>n=1 /\((?:[^"\)]*"(.*?)")?[^"]*?\)/ n=2 /\((?:[^"\)]*"(.*?)")?(?:[^"\)]*"(.*?)")?[^"]*?\)/ n=3 /\((?:[^"\)]*"(.*?)")?(?:[^"\)]*"(.*?)")?(?:[^"\)]*"(.*?)")?[^"]*?\)/ </code></pre> <p>To find 1-N strings you repeat the section <code>(?:[^"\)]*"(.*?)")?</code> N times. For 1-100 strings within each set of parenthesis you would have to repeat that section 100 times - obviously the regex would start evaluating very slowly.</p> <p>I realise that isn't by any means ideal, but its my best effort at a 1 pass solution.</p> <p><strong>In 2 passes:</strong></p> <pre><code>$subject = 'My name is "Ralph" ("France" is my country, "123" my age, ... , "an other text", ...)'; $pattern = '/\(.*?\)/'; preg_match_all($pattern, $subject, $matches); $pattern2 = '/".*?"/'; preg_match_all($pattern2, $matches[0][0], $matches2); print_r($matches2); </code></pre> <p>Produces correct output in 2 passes. Eagerly awaiting an answer that shows how to do it in 1 though. I've tried every variation I could think of, but can't get it to include overlapping matches.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload