3 replies to this topic
#1
Posted 26 November 2012 - 04:54 PM
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?
#2
Posted 26 November 2012 - 06:22 PM
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.
#3
Posted 26 November 2012 - 08:59 PM
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]')
#4
Posted 26 November 2012 - 09:49 PM
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.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












