Improve regex efficiency

* Use non-capturing parentheses to minimize memory usage
* Use whitespace character class instead of explicit space
Add test to allow trailing whitespace
Improve test name