Backslider Posted November 26, 2012 Share Posted November 26, 2012 I need to find valid records as part of a database cleanup script. What I need is a regular expression that will match, for a single column: records containing BOTH numbers AND letters (or any other character). records containing ONLY numbers (including decimals) Invalid records are those which contain ONLY letters and I do not want these returned, or NULL for the column. Anybody good with regex? Quote Link to comment https://forums.phpfreaks.com/topic/271214-regex-help/ Share on other sites More sharing options...
requinix Posted November 26, 2012 Share Posted November 26, 2012 Maybe I'm misreading it but your two conditions are simply "record contains numbers and other stuff OR record contains numbers and not other stuff". Which is really just saying that it has to contain a number. Quote Link to comment https://forums.phpfreaks.com/topic/271214-regex-help/#findComment-1395361 Share on other sites More sharing options...
Backslider Posted November 27, 2012 Author Share Posted November 27, 2012 Hi, thanks for the reply. I actually solved this as follows: SELECT model FROM products WHERE model != '' AND model != '0' AND (model REGEXP '[0-9][a-z]' OR model REGEXP '[0-9]') Quote Link to comment https://forums.phpfreaks.com/topic/271214-regex-help/#findComment-1395387 Share on other sites More sharing options...
requinix Posted November 27, 2012 Share Posted November 27, 2012 Right. And what I'm saying is that model REGEXP "[0-9]" will also include the model!="" (contains something) and model REGEXP "[0-9][a-z]" (contains a number followed by a letter) cases. They're redundant. Still need the !=0 though. Quote Link to comment https://forums.phpfreaks.com/topic/271214-regex-help/#findComment-1395392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.