So I've thought about it and I don't really feel like spending more time to convince you that this works. If you have questions I am happy to answer them, but please write your own code.
That said, as you seem to actually want to do something with the results, you'll take a branch per match anyway, so I don't see the problem.