Thanks guys, I've been studying Regex from various tutorials online since yesterday and I've been souping up the formula.
I've trying to find a way by which I can use preg_replace to modify the user-inputed string for searching the database in the following ways:
1 - If the string includes a non-alfanumeric digit, convert it to "". So, strings like F-15, F.15, F 15 would all end up F_15 which would be the actual string I search the db with (since is the wildcard).
2 - If the string does not include a digit, then separate it. So, F15 would be F_15.
This is the code
$newsearch = preg_replace("/^([a-z+])(\W?)(\d+)/i","\\1_\\3", $oldsearch);
first pattern searches for the first letter digit or digits (the "F"). Second pattern searches for a possible existing non-alphanumeric character (the "-" or "." or space or none). Third pattern searches for the rest of the string regardless of what appears.
In the replacement it makes the new string start with the first pattern, followed by a "_" then continue with the third pattern, ommitting the second completely.
Works like a charm. 😃