easy regexp by

s=raw_input()
while '[' in s:
    p,q=s.find('['),s.find(']')
    s=s[:p]+'('+'|'.join(s[p+1:q])+')'+s[q+1:]
while '?' in s:
    p=s.find('?')
    if s[p-1] == ')':
        q=s[:p].rfind('(')
        s=s[:q+1]+"|"+s[q+1:p]+s[p+1:]
    else:
        s=s[:p-1]+'(|'+s[p-1]+')'+s[p+1:]
o=['']
while s:
    c=s[0]
    if c=='(':
        p=s.find(')')
        o=[i+j for i in o for j in s[1:p].split('|')]
        s=s[p+1:]
    else:
        o=[i+c for i in o]
        s=s[1:]
print'\n'.join(o)

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

download

return to the top page