Re: Searching on AlphaNumeric Content Only

From: Date: Thu, 03 Sep 2009 17:39:48 +0000
Subject: Re: Searching on AlphaNumeric Content Only
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-297642@lists.php.net to get a copy of this message
> Excuse me? Somebody suggested a PHP loop to solve a query problem and you are saying that > REGEXP should not be used? > MySQL caches queries and 100 SELECT with a REGEXP will cost zero after the first one if nothing > changed inside the table. Even if the REGEXP has to change with every query? Performance aside, I think REGEXP() could be used here, but not in the way you've suggested. As the OP has described his table, your regex ("^[a-zA-Z0-9]+$") won't match any rows, because all of his product IDs have non-alphanumeric characters in them. Suppose this table: pk | prod_id 1 | 07-ABCD-98 2 | 98-ZCXQ-21 And now suppose the OP's scenario, where a user tries to search on product id, but enters "07ABCD98". If the aim is to use REGEXP() to return row 1, I suppose you could intersperse the search string with ".?" sequences and end up with this query: SELECT * FROM table WHERE prod_id REGEXP '^0.?7.?A.?B.?C.?D.?9.?8$' I think just stripping the alphanumeric characters would end up being more flexible, though. -Ben

« previous php.general (#297642) next »