[Patches] [ python-Patches-1174589 ] hierarchical regular expression

SourceForge.net noreply at sourceforge.net
Sat Apr 2 01:10:18 CEST 2005


Patches item #1174589, was opened at 2005-04-01 03:59
Message generated for change (Comment added) made by ottrey
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1174589&group_id=5470

Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Chris Ottrey (ottrey)
Assigned to: Nobody/Anonymous (nobody)
Summary: hierarchical regular expression

Initial Comment:
( from the re2 sourceforge project
http://pyre2.sourceforge.net )

The re2 library provides a hierarchical regular
expression extension to the re library.

re2 extracts a hierarchy of named groups from a string,
rather than the flat, incomplete dictionary that the
standard re module returns. 

>>> import re
>>> buf='12 drummers drumming, 11 pipers piping, 10
lords a-leaping'
>>> regex='^((?P<verse>(?P<number>\d+)
(?P<activity>[^,]+))(, )?)*$'
>>> pat1=re.compile(regex)
>>> m=pat1.match(buf)
>>> m.groupdict()
{'verse': '10 lords a-leaping', 'number': '10',
'activity': 'lords a-leaping'}

>>> import re2
>>> buf='12 drummers drumming, 11 pipers piping, 10
lords a-leaping'
>>> regex='^((?P<verse>(?P<number>\d+)
(?P<activity>[^,]+))(, )?)*$'
>>> pat2=re2.compile(regex)
>>> x=pat2.extract(buf)
>>> x
{'verse': [{'number': '12', 'activity': 'drummers
drumming'}, {'number': '11', 'activity': 'pipers
piping'}, {'number': '10', 'activity': 'lords a-leaping'}]}

(See http://pyre2.sourceforge.net/ for more details.)

----------------------------------------------------------------------

>Comment By: Chris Ottrey (ottrey)
Date: 2005-04-01 23:10

Message:
Logged In: YES 
user_id=609576

Sorry, it's more an extension than a patch.
(Although maybe it could be applied as a patch to the re
library.)
(BTW Where is the correct place to submit extensions?)

The code is in this subversion repository:
  http://pintje.servebeer.com/svn/pyre2/trunk/

Or available for download here:
  http://sourceforge.net/project/showfiles.php?group_id=134583

And has a development wiki here:
  http://py.redsoft.be/pyre2/wiki/

And yes, I'm the author.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2005-04-01 19:57

Message:
Logged In: YES 
user_id=21627

Is this a patch? If so, where is the code, and are you its
author?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1174589&group_id=5470


More information about the Patches mailing list