Refactor command filter into a unit tested class.

Also adds support for regex \s as the subcommand delimiter.