You could use positive lookahead assertion, like this:
line vty 0 \d(.*\n)*? transport input ssh(?=\nline)
That would stop the regex, provided the next thing to follow were something other than a newline and the word 'line', starting the next directive. It fails if you change the transport to any.