splitting words with brackets

Qiangning Hong hongqn at gmail.com
Wed Jul 26 17:15:22 EDT 2006


Tim Chase wrote:
> Ah...the picture is becoming a little more clear:
>
>  >>> r = re.compile(r'(?:\([^\)]*\)|\[[^\]]*\]|\S)+')
>  >>> r.findall(s)
> ['(a c)b(c d)', 'e']
>
> It also works on my original test data, and is a cleaner regexp
> than the original.
>
> The clearer the problem, the clearer the answer. :)

Ah, it's exactly what I want!  I thought the left and right sides of
"|" are equal, but it is not true.  I think I must sleep right now,
lacking of sleep makes me a dull :-p.  Thank you and Simon for your
kindly help!




More information about the Python-list mailing list