Question about a regular expression
Darrell
news at dorb.com
Wed Dec 22 09:55:58 EST 1999
This doesn't work if you have nested parens.
>>> s='(1(2))'
>>> print re.search(r"\((.*?)\)",s).groups()
('1(2',)
>>>
Look on deja for 'ASCII delimited files' , which has this same problem.
--
--Darrell
"Rob Hodges" <s323140 at student.uq.edu.au> wrote in message
news:m3puvztau2.fsf at phaedrus.zen.xom...
> Rob Hodges <s323140 at student.uq.edu.au> writes:
>
> > Yoav I H Parish <parish at ikb.mavt.ethz.ch> writes:
> >
> > > i have a string which could look something like
> > >
> > > a(x,y)b(x)
> > > or
> > > c(x,y,z)b(x)a(x,y)
> [...]
> > I'd use a regexp (.*?) to grab the entire contents of each paren pair,
>
> Aarghh! Of course, I meant r"\((.*?)\)" -- you need the real parens as
> well as the grouping parens. Oops,
>
> -Rob
>
> --
> http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list