I have a string that looks like this
[URL of the video].
How can I get the title of the video and the URL of the video in one RegEx match without any other part of the string?
I have a string that looks like this
[URL of the video].
How can I get the title of the video and the URL of the video in one RegEx match without any other part of the string?
 
    
     
    
    Assign capturing groups and use match_obj.groups() to return them as a tuple.
# s is the input string
title, url = re.match(r"!\[.*\]\((.*)\)\[(.*)\]", s).groups()
For the sake of readability, I prefer writing it using re.VERBOSE over a one-liner:
patt = re.compile(r"""
    !
    \[ .* \]    # video
    \( (.*) \)  # group
    \[ (.*) \]  # url
    """, re.VERBOSE)
title, url = patt.match(s).groups()
