for exp in [JSON_REG, NON_JSON_REG]: m = exp.match(output) if m: inner_output = m.groupdict().get('stdout') break . . . . Traceback line 124, in main m = exp.match(output) TypeError: can't use a string pattern on a bytes-like object