<p>I've got a whole host of values stored in a .net 2.0 hashtable.  What I would really like to find is a way to, essentially, do a SQL select statement  on the table.</p>

<p>Meaning, I'd like to get a list of keys whose associated values match a very simple text pattern (along the lines of "starts with a number".)</p>

<p>The final goal will be to remove these records from the hashtable for further processing.</p>

<p>I've been beating my head against this for a while now, and I can't seem to come up with anything.</p>

<p>Any ideas?</p>

<p>(On the off chance this matters: due to the realities of this project, any 3rd party widgets or upgrading to a more recent version of .net are off the table.)</p>

You could use a regex against every key in the hashtable.  This is very dirty but it works:
```
```
static void Main(string[] args)
    {
        Hashtable myhashtable = new Hashtable();
        myhashtable.Add("Teststring", "Hello");
        myhashtable.Add("1TestString1", "World");
        myhashtable.Add("2TestString2", "Test");

        List<String> newht = new List<String>;

        //match all strings with a number at the front
        Regex rx = new Regex("^[1-9]");
        foreach (string key in myhashtable.Keys)
        {
            if (rx.IsMatch(key) == true)
            {
                newht.Add(key);
            }
        }

        //Loop through all the keys in the new collection and remove them from
        //them from the main hashtable.
        foreach (string key in newht)
        {
            myhashtable.Remove(key);
        }
    }
```
```
EDIT: And just for fun, here is the LINQ version (sorry I just had too).
```
```
Hashtable myhashtable = new Hashtable();
            myhashtable.Add("Teststring", "Hello");
            myhashtable.Add("1TestString1", "World");
            myhashtable.Add("2TestString2", "Test");

            Regex rx = new Regex("^[1-9]");
            var k = (from string key in myhashtable.Keys
                     where rx.IsMatch(key)
                     select key).ToList();

            k.ForEach(s => myhashtable.Remove(s));
```
```
EDIT: I have just added list of sting rather then a hashtable, I couldn't remember which .net version had generic lists in it ***slaps forehead