Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, a regex that works on your example could look like this (line breaks introduced to keep this beast legible, need to be removed prior to use):</p> <pre><code>/^(?P&lt;pr_city&gt;[^,]+), (?P&lt;pr_date&gt;[^-]+) - (?P&lt;corp_name&gt;.*?), a (?P&lt;corp_city&gt;[^,]+), (?P&lt;corp_state&gt;[^,]+), establishment is recalling approximately (?P&lt;amount&gt;.*?) of (?P&lt;product&gt;.*?), which is not compliant with regulations that require (?P&lt;reason&gt;.*?), the U\.S\. Department of Agriculture\'s Food Safety and Inspection Service \(FSIS\) announced today\.$/ </code></pre> <p>So, in PHP you could do</p> <pre><code>if (preg_match('/^(?P&lt;pr_city&gt;[^,]+), (?P&lt;pr_date&gt;[^-]+) - (?P&lt;corp_name&gt;.*?), a (?P&lt;corp_city&gt;[^,]+), (?P&lt;corp_state&gt;[^,]+), establishment is recalling approximately (?P&lt;amount&gt;.*?) of (?P&lt;product&gt;.*?), which is not compliant with regulations that require (?P&lt;reason&gt;.*?), the U\.S\. Department of Agriculture\'s Food Safety and Inspection Service \(FSIS\) announced today\.$/', $subject, $regs)) { $prcity = $regs['pr_city']; $prdate = $regs['pr_date']; ... etc. } else { $result = ""; } </code></pre> <p>This assumes a couple of things, for instance that there are no line breaks, and that the input is the entire string (and not a larger string from which this part has to be extracted from). I've tried to make assumptions about legal values that make some sense, but there is the very real chance that other inputs could break this. So some more test cases are probably needed.</p>
 

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