<p>I'm looking to find records in a table that match a specific number that the user enters.  So, the user may enter 12345, but this could be 123zz4-5 in the database.</p>
<p>I imagine something like this would work, if PHP functions worked in MySQL.</p>
<pre><code>SELECT * FROM foo WHERE preg_replace(&quot;/[^0-9]/&quot;,&quot;&quot;,bar) = '12345'
</code></pre>
<p>What's the equivalent function or way to do this with just MySQL?</p>
<p><em>Speed is not important.</em></p>

The simplest way I can think to do it is to use the MySQL REGEXP operator a la:
```
```
WHERE foo LIKE '1\D*2\D*3\D*4\D*5'
```
```
It's not especially pretty but MySQL doesn't have a
```
preg_replace
```
function so I think it's the best you're going to get.
Personally, if this only-numeric data is so important, I'd keep a separate field just to contain the stripped data. It'll make your lookups a lot faster than with the regular expression search.