Advanced search using preg_replace function... ?

I have a site that uses a lot of different part numbers that have hyphens or dashes in various places. I've tried to take as many variations as I can think of and place them into the “search words” field. It's a lot of work and sometimes I find myself doing this in vain. What I'm wanting to do is to have all of my part numbers exclude the hyphen/dash. I read somewhere that I can possibly use the PHP based function called, “preg_replace” to replace or strip a search character.

Example below…

Below are part numbers that I have in the store. Notice the hyphens/dashes. I want to enter them in the store “without” the hyphens and when a customer searches for a part number using a hyphen in the search, the function strips the hyphen from the search, thus locating a match.




Therefore, if I have an item with part number 45YCTI984, and a user searches for 45YCTI9-84, 45Y-CTI984, 4-5YCTI984, or 45YCTI98-4; it will strip the hyphen and locate the match of 45YCTI984.

Google fully utilizes this feature in their searches, which make it very powerful. Does anyone know anything about how to implement this into the search function of the cart?


Did you have any luck with this?? I want to do EXACTLY the same thing and I can't figure it out!

Best to do this with Javascript. Something like this should get you started.

$("#myForm").submit(function() {
$("input, textarea").each(function() {
$(this).val($(this).val().replace(/[^a-zA-Z0-9 ]/g, ''));