Steve Newcomb added the comment:

I have re-read the documentation on re.sub().  Even now, now that I understand 
that the \g<groupname> syntax applies to the repl argument only, I cannot see 
how the documentation can be understood that way.  The paragraph in which the 
explanation of the \g<groupname> syntax appears does not mention the repl 
argument by name, and neither does the preceding paragraph. 

The paragraph before the preceding paragraph is about the pattern argument, not 
the repl argument, and it consists entirely of the words, "The pattern may be a 
string or an RE object." 

So I don't see how the explanation of the \g<groupname> syntax can be 
understood as applying only to the repl argument, even though you have now 
informed me that that's the case (which is helpful to know -- thanks!).  
Indeed, the paragraph that explains the \g<groupname> syntax *still* appears to 
me to be discussing the pattern argument.  And it even mentions the <?P<name> 
syntax, which can only appear in a pattern, not in a repl, in the very same 
sentence as the \g<groupname> syntax, even though those two syntactic features 
appear in *different* expression languages, and no single expression language 
has both of them.  

So there is no clear indication that it is discussing two different expression 
languages.  Indeed, another syntactic feature, \groupnumber, also discussed in 
the same paragraph, *is* found in both expression languages, so it's even more 
confusing to a person who knows that both <?P<groupname> and \groupnumber 
appear in the pattern expression language.  There is nothing in the 
documentation that would inform a person (such as myself) that the 
\g<groupname> syntax is not also part of the pattern expression language, just 
as the other two features are.

(And why isn't \g<groupname> part of the pattern language, anyway, or at least 
some way to refer to a match made in a previous *named* group?  It would be 
very convenient to be able to do that, particularly when using a 
dynamically-created regexp to parse strings delimited with a choice of 
delimiters that must match at both ends.)

In other words, this documentation could be beneficially improved.

----------
resolution: invalid -> 
status: closed -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15956>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to