easy regexp by tabasa

import re\x0d
li=raw_input()\x0d
ans=[]\x0d
\x0d
def Or(a):\x0d
 ans=[]\x0d
 ans+=a.split("|")\x0d
 return [ans]\x0d
\x0d
def hate(a):\x0d
 ans=[""]\x0d
 if type(a)==type(""):\x0d
  ans+=a\x0d
 else:\x0d
  ans+=a\x0d
 return [ans]\x0d
\x0d
def chars(a):\x0d
 return [a[i] for i in range(len(a))]\x0d
\x0d
last=""\x0d
le=len(li)\x0d
i=0\x0d
c=""\x0d
hatef=0\x0d
while i<le:\x0d
 c=li[i]\x0d
 if c=='?':\x0d
  hatef=1\x0d
  ans+=hate(last) \x0d
  last=c\x0d
  i+=1\x0d
 else:\x0d
  hatef=0\x0d
  if (last !='?')and(i>0):ans+=last\x0d
  if c=='(':\x0d
   matc=re.search('\(([^)]+)\)',li[i:]).group(1)\x0d
   i+=len(matc)+2\x0d
   last=Or(matc)\x0d
  elif c=='[':\x0d
   matc=re.search('\[([^\]]+)\]',li[i:]).group(1)\x0d
   i+=len(matc)+2\x0d
   last=[chars(matc)]\x0d
  else:\x0d
   last=c\x0d
   i+=1\x0d
if hatef==0:ans+=last \x0d
\x0d
def put(an,a,l,n):\x0d
 if l==n:\x0d
  print an\x0d
 else:\x0d
  if type(a[n])==type(""):\x0d
   an+=a[n] \x0d
   put(an,a,l,n+1)\x0d
  else:\x0d
   for i in a[n]:\x0d
    if type(i)==type(""):\x0d
     put(an+i,a,l,n+1)\x0d
    elif type(i)==type([]):\x0d
     for j in i:put( an+j,a,l,n+1)\x0d
\x0d
put("",ans,len(ans),0)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page