Re: splitting words with brackets
- From: "Qiangning Hong" <hongqn@xxxxxxxxx>
- Date: 26 Jul 2006 13:42:48 -0700
Tim Chase wrote:
>>> import re[...]
>>> s ='a (b c) d [e f g] h ia abcd(b c)xyz d [e f g] h i'
>>> r = re.compile(r'(?:\S*(?:\([^\)]*\)|\[[^\]]*\])\S*)|\S+')
>>> r.findall(s)
['a', '(b c)', 'd', '[e f g]', 'h', 'ia', 'abcd(b c)xyz', 'd',
'[e f g]', 'h', 'i']
However, the above monstrosity passes the tests I threw at
it.
but it can't pass this one: "(a c)b(c d) e"
the above regex gives out ['(a c)b(c', 'd)', 'e'], but the correct one
should be ['(a c)b(c d)', 'e']
.
- Follow-Ups:
- Re: splitting words with brackets
- From: Tim Chase
- Re: splitting words with brackets
- From: Simon Forman
- Re: splitting words with brackets
- References:
- splitting words with brackets
- From: Qiangning Hong
- Re: splitting words with brackets
- From: Tim Chase
- splitting words with brackets
- Prev by Date: Re: splitting words with brackets
- Next by Date: Re: How to force a thread to stop
- Previous by thread: Re: splitting words with brackets
- Next by thread: Re: splitting words with brackets
- Index(es):