It seems to me like we should be able to trim the whitespace directly in the regex. Maybe doing the same `[\r\n]` trick as in #726 would work?