The SQL regex stuff others have posted is one way to do it, but note
that scanning a table like that is inherently going to be slow, and
will get slower as the table gets bigger.
If you're doing this operation a lot, it might be valuable to pre-
compute the number strings for the identifier field, like this:
class Patient
# add a new field, identifier_numbers perhaps
before_save :sanitize_indentifier
def sanitize_identifier
self.identifier_numbers = identifier.gsub(/[^0-9]/,"") if
identifier
end
end
Then you can just search against identifier_numbers.
--Matt Jones
On Aug 28, 10:30 am, Aldric Giacomoni <rails-mailing-l...@andreas-
s.net> wrote:
> Say I have a string : "012345678".
> I have a column in a table which also stores strings. I want to find all
> rows which match that string of numbers in that order.
> That is, "012345678" will match, but "012-34-5678" will, and
> "012sneeze345bless67you8thanks" also will.
>
> Do I have to do something like:
> ThisIsMyString = "012345678"
> fits = Patient.all.find { |a| a.identifier.delete("^[0-9]") ==
> ThisIsMyString }
>
> .. Or can I do something WITHOUT getting all the data, a kind of
> Patient.find but with a tweak on the sql query?
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---