[Python-Dev] hierarchicial named groups extension to the re library

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Sun Apr 3 11:13:51 CEST 2005



ottrey at py.redsoft.be a écrit :
> Nicolas Fleury <nidoizo at yahoo.com> wrote:
 >
> [...]
> 
> Actually, I ~would~ like to limit it to just named groups.
> I reckon, if you're not going to bother naming a group, then why would
> you have any interest in it.
> I guess its up for discussion how confusing this "new" way of thinking
> could be and what drawbacks it might have.

I would find interesting to match every groups without naming them ! For 
example, if the position in the father group is the best meaning, why 
bother with names ? If you just allow the user to skip the compression 
stage it will do the trick !

That leads me to a question: would it be possible to use, as names for 
unnamed groups, integers instead of strings ? That way, you could access 
unnamed groups by their rank in their father group for example.

A small example of what I would want:

 >>> buf="123 234 345, 123 256, and 123 289"
 >>> regex=r'^(( *\d+)+,)+ *(?P<logic>[^ ]+)(( *\d+)+).*$'
 >>> pat2=re2.compile(regex)
 >>> x=pat2.extract(buf)
 >>> x
{ 0: {'_value': "123 234 345,", 0: "123", 1: " 234", 2: " 345"},
   1: {'_value': " 123 256,", 0: " 123", 1:" 256"},
   'logic': {'_value': 'and'},
   3: {'_value': " 123 289", 1: " 123", 2:" 289"} }

Pierre

> 
> Regards.
> 
> Chris.
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/pierre.barbier%40cirad.fr
> 

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68


More information about the Python-Dev mailing list