2

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?

Trip
  • 26,756
  • 46
  • 158
  • 277

2 Answers2

2

You can use rlike / regexp i would think. Though it's not portable across to other databases.

http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp

Object.where(['name rlike ?', '^[\d]'])
Omar Qureshi
  • 8,963
  • 3
  • 33
  • 35
2

Select values that begin with a number

Object.where(['name REGEXP ?', '^[0-9]'])
Community
  • 1
  • 1
Lee Jarvis
  • 16,031
  • 4
  • 38
  • 40