 <p>First, remove stuff that shouldn't be there:</p> <pre><code>$str = preg_replace('/[^PDL\d-]/i', '', $str); </code></pre> <p>That gives you the following normalised results:</p> <pre class="lang-none prettyprint-override"><code>D456789-1 D456789-1 D456789-1ldlddld </code></pre> <p>Then, attempt to match the data you want:</p> <pre><code>if (preg_match('/^([PDL])(\d+-\d)/i', $str, $match)) { $code = $match[1]; $load = $match[2]; } else { // uh oh, something wrong with the format! } </code></pre>