0

My variable column could either be a string or a number/float. I need to use my regex to catch both 20000 and "20000". Right now my regex is /^#{column}$/i which only catches the string "20000". In addition to this, I need it to stay case insensitive which it currently is.

I am using Mongoid to query a mongo database. The whole query is

Mongoid.client("default")["table_name"].find({ field: /^#{row[column]}$/i })
brandoncodes
  • 123
  • 1
  • 12
  • I don't understand the question. What do you mean by "match a number with a regex"? -- You can't. You could either just *check if it's a number*, or convert it to a string first. What does `/^#{column}$/i` mean? (What is `column`?) – Tom Lord Oct 24 '17 at 15:23
  • Sorry, I forgot to include that it is a Mongo query. So in my database I could have a value of 20000 which is a number, or I could have `"20000"` and my regex would need to capture both of these values. – brandoncodes Oct 24 '17 at 15:29

0 Answers0