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,093
  • 43
  • 151
  • 267

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,773
  • 3
  • 32
  • 35
2

Select values that begin with a number

Object.where(['name REGEXP ?', '^[0-9]'])
Community
  • 1
  • 1
Lee Jarvis
  • 15,553
  • 4
  • 37
  • 40