 <p>The following samples are all matched.</p> <pre><code>$samples = Array( 'what is 4+3', 'what is 2 plus 7', 'what is 3 * 2', 'what is 3x2', 'what is 4 times 2' ); foreach($samples as $sample) { $sample = preg_replace('/(times)|\*/', 'x', $sample); $sample = str_replace('plus', '+', $sample); preg_match('/what is \d ?[+x] ?\d/', $sample, $matches); var_dump($matches[0]); } </code></pre> <p>A bit nicer in JavaScript. Just including this for the fun of it.</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var samples = [ 'what is 4+3', 'what is 2 plus 7', 'what is 3 * 2', 'what is 3x2', 'what is 4 times 2' ]; samples.forEach(function(sample) { sample = sample .replace(/(times)|\*/, 'x') .replace('plus', '+') ; var match = sample.match(/what is \d ?[+x] ?\d/); console.log(match); });</code></pre> </div> </div> </p>