fixes #2685 incorrect and inefficient regexp checking medium name format

It takes eternity to compute something like this:

"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  b" =~ /\A(\S+\s?)+\Z

Also "this is wrong " was not matched
(cherry picked from commit cd2892774b6f6073bb189bd17ea7fcaec76388e6)