def find_text(text, matches=lambda x: x.group(1) if x else ''):
    return matches(PATTERN.search(text))
assert find_text('foo=bar,key=value,beer=pub') == 'value'
assert find_text('no match here') == ''
Getting captured group in one line