I'm trying to find objects that begin with a number.
我正在尝试找到以数字开头的对象。
Syntactically this is off. But I would like to do something like this :
从句法上说这是关闭的。但我想做这样的事情:
Object.where([name LIKE ?', /[1-9]/])
If that isn't possible, how do you suppose the best way to find all objects that start with a number?
如果那是不可能的,那么您如何设想找到以数字开头的所有对象的最佳方法?
2 个解决方案
#2
2
You can use rlike / regexp i would think. Though it's not portable across to other databases.
您可以使用rlike / regexp。虽然它不可移植到其他数据库。
http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
Object.where(['name rlike ?', '^[\d]'])
#1
#2
2
You can use rlike / regexp i would think. Though it's not portable across to other databases.
您可以使用rlike / regexp。虽然它不可移植到其他数据库。
http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
Object.where(['name rlike ?', '^[\d]'])