Re: splitting words with brackets
- From: Tim Chase <python.list@xxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Jul 2006 21:11:28 -0500
>>> r = re.compile(r'(?:\([^\)]*\)|\[[^\]]*\]|\S)+')
>>> r.findall(s)
['(a c)b(c d)', 'e']
Ah, it's exactly what I want! I thought the left and right sides of "|" are equal, but it is not true.
In theory, they *should* be equal. I was baffled by the nonparity
of the situation. You *should" be able to swap the two sides of the "|" and have it treated the same. Yet, when I tried it with the above regexp, putting the \S first, it seemed to choke and give different results. I'd love to know why.
Thank you and Simon for your kindly help!
My pleasure. A nice diversion from swatting spammers and getting our network back up and running today. I had hoped to actually get something productive done (i.e. writing some python code) rather than putting out fires. Sigh.
-tkc
.
- Follow-Ups:
- Re: splitting words with brackets
- From: Paul McGuire
- Re: splitting words with brackets
- References:
- splitting words with brackets
- From: Qiangning Hong
- Re: splitting words with brackets
- From: Tim Chase
- Re: splitting words with brackets
- From: Qiangning Hong
- Re: splitting words with brackets
- From: Tim Chase
- Re: splitting words with brackets
- From: Qiangning Hong
- splitting words with brackets
- Prev by Date: subprocess module
- Next by Date: Weekly Python Patch/Bug Summary
- Previous by thread: Re: splitting words with brackets
- Next by thread: Re: splitting words with brackets
- Index(es):
Relevant Pages
|
|