Recursive regexps?

James Stroud jstroud at mbi.ucla.edu
Fri Nov 19 18:39:02 EST 2004


This may or may not be topical to the original post, but I think this would be 
cool in python:

>>> string = "abc 123 456 abc"
>>> import re
>>> regex = re.compile(r'(abc (\d+ )+abc)')
>>> s = regex.match(string)
>>> s.groups()
('abc 123 123 abc', ('123 ', '456 '))

(or similar), instead of

>>> s.groups()
('abc 123 123 abc', '123 ')


I dont have a CS degree, but I'm pretty sure that computers can do this sort 
of thing. It must not be obvious. I'm thinking of patenting the idea (regex 
engine returns nested matches) and copyrighting the name for it.

James

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/



More information about the Python-list mailing list