I am not at all good with regexps. Definitely would want a review with a regexp expert like @dmitchell.