[Python-ideas] Improving Clarity of re Module

spir denis.spir at gmail.com
Tue Nov 26 23:52:42 CET 2013


On 11/26/2013 11:31 PM, 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.

I do agree and support such a change. Actually, I remember it took me some time 
to find that expression, precisely. (However, isn't it group() alone, without 0? 
Haven't used re for a while...) But "m.matchspan" is for the least redondant 
(since m is a match result). "m.span" or "m.snippet" would nicely do the job, 
wouldn't it?

> 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?

At first sight, does not seem that complicated (also, the code exist for 
group()). How clear is  the existing implementation?

Denis


More information about the Python-ideas mailing list