[issue4882] Behavior of backreferences to named groups in regular expressions unclear

2009-02-10 Thread alec resnick

alec resnick aresnick...@gmail.com added the comment:

Hi Georg!

Sorry to be so long in getting back to you.  I've attached a suggested
patch for the python-2.6.1-docs-text/library/re.txt documentation.
Also, in looking over Kuchling's HOWTO, the necessary information is
actually there, and I just wasn't paying attention =)  Let me know if
I should do something else--this is my first 'fix'/submission to
Python, and I'm eager for feedback.

Thanks!

Gratefully,
a.

--
keywords: +patch
Added file: 
http://bugs.python.org/file13016/re-backreference-clarification.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4882
___*** /home/aresnick/Desktop/python-2.6.1-docs-text/library/re.txt
2009-01-04 01:25:41.0 -0500
--- modified-re.txt 2009-02-10 12:38:30.0 -0500
***
*** 242,254 
 or referenced later in the pattern.
  
  ``(?Pname...)``
 Similar to regular parentheses, but the substring matched by the
!group is accessible via the symbolic group name *name*.  Group
!names must be valid Python identifiers, and each group name must be
!defined only once within a regular expression.  A symbolic group is
!also a numbered group, just as if the group were not named.  So the
!group named 'id' in the example below can also be referenced as the
!numbered group 1.
  
 For example, if the pattern is ``(?Pid[a-zA-Z_]\w*)``, the group
 can be referenced by its name in arguments to methods of match
--- 242,256 
 or referenced later in the pattern.
  
  ``(?Pname...)``
+ 
 Similar to regular parentheses, but the substring matched by the
!group is accessible within the rest of the regular expression via
!the symbolic group name *name*.  Group names must be valid Python
!identifiers, and each group name must be defined only once within a
!regular expression.  A symbolic group is also a numbered group,
!just as if the group were not named.  So the group named 'id' in
!the example below can also be referenced (within the regular
!expression) as the numbered group 1.
  
 For example, if the pattern is ``(?Pid[a-zA-Z_]\w*)``, the group
 can be referenced by its name in arguments to methods of match
***
*** 256,264 
 name in pattern text (for example, ``(?P=id)``) and replacement
 text (such as ``\gid``).
  
! ``(?P=name)``
 Matches whatever text was matched by the earlier group named
!*name*.
  
  ``(?#...)``
 A comment; the contents of the parentheses are simply ignored.
--- 258,268 
 name in pattern text (for example, ``(?P=id)``) and replacement
 text (such as ``\gid``).
  
! ``(?P=name)`` 
 Matches whatever text was matched by the earlier group named
!*name*.  This can only be used within the regular expression.  To
!reference the captured group, pass the group's name as an argument
!to the method of a match object, e.g. ``m.group('name')``.
  
  ``(?#...)``
 A comment; the contents of the parentheses are simply ignored.
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4882] Behavior of backreferences to named groups in regular expressions unclear

2009-01-08 Thread alec resnick

New submission from alec resnick aresnick...@gmail.com:

I recently learned about named groups in Python regular expressions. 
Almost all the documentation I've found online explains what they are
and give a simple example of how to use them.  I was trying to use the
variables outside of the original regex, later in the code.  Nowhere in
the documentation I found after a couple hours of searching was it
mentioned that named groups can only be backreferenced _within_ the pattern.

In particular, the sections at
http://www.amk.ca/python/howto/regex/#SECTION00053 and
the description of the (?Pname) behavior at
http://docs.python.org/library/re.html could be modified to make it
clear that the named capture does not create a variable usable outside
of the pattern.

I would be happy to alter the documentation appropriately.

--
assignee: georg.brandl
components: Documentation
messages: 79417
nosy: aresnick, georg.brandl
severity: normal
status: open
title: Behavior of backreferences to named groups in regular expressions unclear
type: feature request
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4882
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com