T
Timur Tabi
I'm having trouble creating a regex pattern that matches a string that
has an optional substring in it. What I'm looking for is a pattern
that matches both of these strings:
Subject: [PATCH 08/18] This is the patch name
Subject: This is the patch name
What I want is to extract the "This is the patch name". I tried this:
m = re.search('Subject:\s*(\[[\w\s]*\])*(.*)', x)
Unfortunately, the second group appears to be too greedy, and returns
this:
Can anyone help me? I'd hate to have to use two regex patterns, one
with the [...] and one without.
has an optional substring in it. What I'm looking for is a pattern
that matches both of these strings:
Subject: [PATCH 08/18] This is the patch name
Subject: This is the patch name
What I want is to extract the "This is the patch name". I tried this:
m = re.search('Subject:\s*(\[[\w\s]*\])*(.*)', x)
Unfortunately, the second group appears to be too greedy, and returns
this:
print m.group(1) None
print m.group(2) [PATCH 08/18] Subject line
Can anyone help me? I'd hate to have to use two regex patterns, one
with the [...] and one without.