Question: I am looking for an elegant way, preferably a short linq expression, to count how many alphanumeric chars a given string contains.

The 'boring' way I do it now is this:

```
int num = 0;
for (int i = 0; i < password.Length; i++)
{
    if (!char.IsLetterOrDigit(password, i))
    {
        num++;
    }
}
if (num < MinRequiredNonAlphanumericCharacters)
    return false;

```

This is rather short already, but I am sure with some linq magic this can be done in an even shorter, equally understandable expression, right?

Answer: 
```
int num = password.Where((t, i) => !char.IsLetterOrDigit(password, i)).Count();

if (num < MinRequiredNonAlphanumericCharacters)
    return false;

```
You could do it with one line of Regex. Whether that's understandable is a moot point.

```
num = new Regex(@"\w", RegexOptions.IgnoreCase).Matches(input).Count

```