4 ms·
The original article already relies on finding multiple matches, in order to ignore the matches that don't contain the group that we're interested in. Python's
by rntz 11y ago
The original article already relies on finding multiple matches, in order to ignore the matches that don't contain the group that we're interested in.
Python's regex library, for example, can return multiple matches. It has three functions:
- `re.match`, which checks whether the whole string matches.
- `re.search`, which checks for the first location in the string that matches.
- `re.findall`, which finds "all" non-overlapping matches.
I was simply suggesting that the "non-overlapping" constraint in findall is a "bug", in some sense, because it exposes implementation details of the regex engine.
But, again, given that it is apparently a useful bug, maybe I am wrong. But that leaves open the question what the right spec for regex matching is, anyway.