Fixed pandoc version detection.

This should make the version detection of pandoc more robust. It should fix issue #6240.
I think it's simpler to just do `version_pattern.search(out_lines[0])`, rather than iterating through tokens in Python land. Really, I think the only changes needed from the original code are:

- Make the regex pattern a bit more general
- Search only the first line instead of all the output