Python regex on numbers
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 loose lots of other possibilities (like
gt/lt, sorting etc.)
Thanks in advance.
No comments:
Post a Comment