Pythonic way of writing multiple regex tests
<p>How to write in a Pythonic way when there are multiple regex patterns to test with and extract matched groups if a test succeeds?</p>

<p>That is to say, what is the Pythonic equivalent of the following code snippet?</p>

<pre><code>if re.match(pattern1, string):
    m = re.match(pattern1, string)
    grps = m.groups()
    ...[process matched groups for pattern1]...
elif re.match(pattern2, string):
    m = re.match(pattern2, string)
    grps = m.groups()
    ...[process matched groups for pattern2]...
elif re.match(pattern3, string):
    m = re.match(pattern3, string)
    grps = m.groups()
    ...[process matched groups for pattern3]...
</code></pre>

<pre><code>patterns = [pattern1, pattern2, pattern3]
for pattern in patterns:
    m = re.match(pattern, string)
    if m:
        grps = m.groups()
        ...
        break
</code></pre>

python