The simplest approach is probably best.
vector<pair<regex,Object>> regexes;
Object* find_it( string looking_for )
{
auto found = find_if( regexes, [&]( const pair<regex,Object>& thing )
{
return get<0>(thing).match(looking_for);
}
if( found != regexes.end() ) return & get<1>(*found);
return nullptr;
}
But, the simple approach is never a fun answer. If you use a Trie you can essentially have fast look up for regexes of the style <prefix>.*
. With a little imagination you might be able to muster good look up time for slightly more expressive "regexes". I, however, doubt you could transform a trie to efficiently handle general regexes. But it could be fun to ... trie :).