 <pre><code>if (preg_match('/\b\d{4}-\d{2}-\d{2}\b/' $str)) { // ... } </code></pre> <p>If the word boundary (<code>\b</code>) doesn't do the trick, you could try <a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow">negative lookbehind and lookaheads</a>:</p> <pre><code>if (preg_match('/(?&lt;!\d)\d{4}-\d{2}-\d{2}(?!\d)/' $str)) { // ... } </code></pre> <p>As an additional validation, you could use <a href="http://php.net/manual/en/function.checkdate.php" rel="nofollow"><code>checkdate()</code></a> to weed out invalid dates such as <code>9999-02-31</code> as mentioned in <a href="http://stackoverflow.com/a/10476175/166339">this answer</a>.</p>