Is it possible to use regex on a number instead of a string?
For example: I have a field in a mongodb that contains the numeric value 1234567 (not stored as a string for sorting purposes etc.). Now I want to use regex to find parts of this number, i.e. 456.
On a database-field that contains a string "1234567"
this is easy: I just pass re.compile("456")
to my database query. However re.compile(456)
gets me the following:
TypeError: first argument must be string or compiled pattern
Any hints on how to accomplish this? Storing my numbers as strings is not really an option, since I would lose lots of other possibilities (like gt/lt, sorting etc.).
Update: Also, I'm passing the regex right into the db-query to filter results, so I cannot pull up an individual field, convert it's content to a string and then use the regex on it.