group(id)
or
group(id1, id2)
group identifiers (typically numbers from 1). No identifier or
an identifier of 0 gives the whole matched substring.
groups(nullMatch)
Gives all the substring matches back as a tuple. The optional
argument allows a value to be specified for pattern groups
that legitimately match nothing, otherwise these give None.
start(id)
The start position of a given group within the queried string.
end(id)
The end position of a given group within the queried string.
span(id)
The start and end positions of a given group within the
queried string.
And in practice it is often best to use the Python module email to deal with this sort of
thing. 2
This can also be done with the re.I flag for case-insensitive searching, but that would
Note that the first argument to sub() is the substring replacement and the second
argument is the string being modified.