Question: Problem
=======

Build a regex statement that allows the following:

1. minimum 5 characters
2. maximum 10 characters
3. can contain whitespace but whitespace does not increment character count
4. any non-whitespace characters increment character count

Test Cases:
-----------

```
 expected_to_pass = ['testa', ' test a', 12342, 1.234, 'test a']
 expected_to_fail = [' test', 'test ', ' test ', '     ', 1234, 0.1, '           ','12345678901']

```

Example regex statements and their purpose
------------------------------------------

**Allow 5-10 non-whitespace characters:**

```
[\S]{5,10}$

```

**Allow 5-10 characters regardless of whitespace:**

```
[\s\S]{5,10}$

```

I've been farting around with this for a few hours and cannot think of the best way to handle this.

Answer: 
How's this?

```
\s*(?:[\w\.]\s*){5,10}+$

```

Or:

```
\s*(?:[\w\.]\s*){5,10}$

```

Also, if ANY non-whitespace character goes:

```
\s*(?:\S\s*){5,10}$

```

You can test it [here](https://regex101.com/r/DsvRZY/3)
There is a wrong assumption in your question: `\w` doesn't match all non-space-characters, it matches word characters - this means letters, digits and the underscore. Depending on language and flags set, this might include or exclude unicode letters and digits. There are a lot more non-space-characters, e.g. `.` and `|`. To match space-characters one usually uses `\s`, thus `\S` matches non-space-characters.

You can use ^\s\*(?:\S\s\*){5,10}$ to check your requirements. You might be able to drop the anchors, if you use some kind of full match functionality (e.g. Java `.matches()` or Python `re.fullmatch`).

Depending on the language you use, you might not want to use a regex, but iterate over the string and check character for character. This should usually be faster than regex. 

Pseudocode:

```
number of chars = 0
for first character of string to last character of string
  if character is space
     inc number of chars by 1
return true if number of chars between 5 and 10

```