splitting words with brackets

Qiangning Hong hongqn at gmail.com
Wed Jul 26 16:50:01 EDT 2006


Simon Forman wrote:
> def splitup(s):
>     return re.findall('''
>         \S*\( [^\)]* \)\S*  |
>         \S*\[ [^\]]* \]\S*  |
>         \S+
>         ''', s, re.VERBOSE)

Yours is the same as Tim's, it can't handle a word with two or more
brackets pairs, too.

I tried to change the "\S*\([^\)]*\)\S*" part to "(\S|\([^\)]*\))*",
but it turns out to a mess.




More information about the Python-list mailing list