Re: splitting words with brackets



>>> 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






.



Relevant Pages

  • Re: Word 2003: That Nasty "Diks Full" bug
    ... You are correct in assuming that none of the writing is done to removable ... last night I copied one of the documents from the network ... removable media drive? ... We have a template stored somewhere on our network. ...
    (microsoft.public.word.application.errors)
  • Re: WMI AD/OU NIC description and StaticIP
    ... Since writing this i've made some progress i.e. NetConnectionID ... which could query a Active Directory or Organizational Unit for a list ... then query this list and return all active NIC cards which ... can be configured in the control panel network properties in the win ...
    (microsoft.public.win32.programmer.wmi)
  • vim advanced folding
    ... As I am writing a lot of python code right now, ... In python a function/method declaration (including documentation ... just below that as the one it displays when the fold is closed? ... I thought about it when writing this. ...
    (comp.editors)
  • RE: Restricting access to a CD-WR drive on a Win2K Server
    ... Are they using some software to access it over the network, ... how do they prevent multiple people from writing at the same ... that, then go down and burn that to disc, or have someone go down every so ... (Maybe and Admin. ...
    (Focus-Microsoft)
  • Re: Who opens my file?
    ... events trigger the writing of data to a text file. ... of your app will be running on a network, and if there is a spot on ...     On Error GoTo EndMacro: ...
    (microsoft.public.excel.programming)