Regex matching keys in a Dictionary
Here are some problems I see with your code:


The code removes the Dictionary's constant-time lookup.
The code reparses the pattern and recompiles each regex every time you're
in the loop.
The code uses regex's even for simple lookups.
The code will die if you try to assign more than one handler to an event.
This might just be an artifact of you copying/pasting, but the indenting on your method is a little unusual.
The code does not favor composition over inheritance.
Your parameter name does not follow the convention of being camelCase.
Your regex pattern doesn't require the beginning and ends, so e.g. as?f matches the same things as *as?f*.


I would use the built-in Dictionary lookup functionality for simple (no-wildcard) lookups and store compiled regex's for the ones with wildcards. Also, you can look at the reference source in your link to get an idea of how to solve the problem of multiple handlers for an event.

This should be a good starting point, with code to add a listener and get handlers. It only uses regex's when needed, keeping them precompiled in a second Dictionary. If the "*" case is pretty common, you could further improve this by handling that as a special case: you don't really need to compile and store a Regex for it, you just always run it. This would probably be a third field, maybe private Delegate universalHandlers;

public class EventDictionary
{
    private readonly Dictionary&lt;string, Delegate&gt; eventTable = new Dictionary&lt;string, Delegate&gt;();
    private readonly Dictionary&lt;string, Regex&gt; regexTable = new Dictionary&lt;string, Regex&gt;();

    private bool HasWildcards(string pattern)
    {
        return pattern.Contains("*") || pattern.Contains("?");
    }

    public void AddListener(string eventType, Delegate eventDelegate)
    {
        Delegate currentDelegate;
        if (eventTable.TryGetValue(eventType, out currentDelegate))
        {
            var d = eventTable[eventType];
            if (d != null &amp;&amp; d.GetType() != eventDelegate.GetType())
                throw new ArgumentException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, eventType.GetType().Name));
            eventTable[eventType] = Delegate.Combine(currentDelegate, eventDelegate);
        }
        else
        {
            eventTable.Add(eventType, eventDelegate);
        }

        if (HasWildcards(eventType) &amp;&amp; !regexTable.ContainsKey(eventType))
            regexTable.Add(eventType, new Regex("^" + Regex.Escape(eventType).Replace(@"\*", ".*").Replace(@"\?", ".") + "$"));
    }

    // TODO implement remove method

    public Delegate GetHandlers(string eventType)
    {
        Delegate handler;
        eventTable.TryGetValue(eventType, out handler);
        foreach (var pair in regexTable)
            if (pair.Value.IsMatch(eventType))
                handler = Delegate.Combine(handler, eventTable[pair.Key]);
        UnityEngine.Debug.Log(handler.GetInvocationList().Length);
        return handler;
    }
}