I have a list of numbers that I want to find at least 3 of... here is an example
I have a large list of numbers in a sql database in the format of (for example)
01-02-03-04-05-06
06-08-19-24-25-36
etc etc basically 6 random numbers between 0 and 99.
Now I want to find the strings where at least 3 of a set of given numbers occurs. For example:
given: 01-02-03-10-11-12 return the strings that have at least 3 of those numbers in them. eg
01-05-06-09-10-12 would match
03-08-10-12-18-22 would match
03-09-12-18-22-38 would not
I am thinking that there might be some algorithm or even regular expression that could match this... but my lack of computer science textbook experience is tripping me up I think.
No - this is not a homework question! This is for an actual application!
I am developing in ruby, but any language answer would be appreciated
You can use a string replacement to replace -
with |
to turn 01-02-03-10-11-12
into 01|02|03|10|11|12
. Then wrap it like this:
((01|02|03|10|11|12).*){3}
This will find any of the digit pairs, then ignore any number of characters... 3 times. If it matches, then success.