How can I efficiently determine if a given string contains two strings?
For example, let's say I'm given the string: abc-def-jk-l. This string either contains two strings divided by a -, or it's not a match. The matching possibilities are:
Possible Matches for "abc-def-jk-l" :
abc def-jk-l
abc-def jk-l
abc-def-jk l
Now, here are my columns of strings to match:
Column I Column II
------- -------
1. abc-def A. qwe-rt
2. ghijkl B. yui-op
3. mn-op-qr C. as-df-gh
4. stuvw D. jk-l
How can I efficiently check to see if the given string matches two strings in the columns above? (The above is a match - matching abc-def and jk-l)
Here are some more examples:
abc-def-yui-op [MATCH - Matches 1-B]
abc-def-zxc-v [NO MATCH - Matches 1, but not any in column II.]
stuvw-jk-l [MATCH - Matches 4-D]
mn-op-qr-jk-l [Is this a match?]
Now, given a strings above, how can I efficiently determine matches? (Efficiency will be key, because columns i and ii will each have millions of rows on indexed columns in their respected tables!)
UPDATE: The order will always be column i, then column ii. (or "no match", which could mean it matches only one column or none)
Here's some php to help:
<?php
$arrStrings = array('abc-def-yui-op','abc-def-zxc-v','stuvw-jk-l','stuvw-jk-l');
foreach($arrStrings as $string) {
print_r(stringMatchCheck($string));
}
function stringMatchCheck($string) {
$arrI = array('abc-def','ghijkl','mn-op-qr','stuvw');
$arrII = array('qwe-rt','yui-op','as-df-gh','jk-l');
// magic stackoverflow help goes here!
if ()
return array($match[0],$match[1]);
else
return false;
}
?>