regex.extract(string, expression [, substitution] [, no_match])
Returns the result of extracting the regular expression from the string, optionally with a substitution expression and a specified result if no match is found.Returns an empty string, or the string specified in
no_match if the expression does not match. If the string specified was
none, an empty string is returned.
The optional substitution expression is used to store groups that match the search expression. The first group is stored in
\1, the second in
\2, and so forth. For example:
A versioning string is of the form "Version 2.7.182 patch 69". To extract the patch number, the following function is used:
patch (\d+) matches
patch 69 in the versioning string and it contains the first group matching
\1 which is
69. If the versioning string was "Version 2.7.182 patch 69 patch 70" then the second group matching
If the versioning string was "Version 2.7.182", the function would return "Unsupported."