[Python-ideas] Improving Clarity of re Module

MRAB python at mrabarnett.plus.com
Tue Nov 26 23:46:24 CET 2013


On 26/11/2013 22:31, Alex Seewald wrote:
> For a match object, m, m.group(0) is the semantics for accessing the
> entire span of the match. For newcomers to regular expressions who are
> not familiar with the concept of a 'group', the name group(0) is
> counter-intuitive. A more natural-language-esque alias to group(0),
> perhaps 'matchSpan', could reduce the time novices spend from idea to
> working code. Of course, this convenience would introduce a bit of
> complexity to the codebase, so it may or may not be worth it to add an
> alias to group(0). What do people think?
>
Well, including 'span' in the name would be confusing because it
already has a .span method which returns the start and end indexes.

I think that for newcomers to regexes, the concept of capture groups is
one of the easiest things to understand!


More information about the Python-ideas mailing list