regex - Python Regular Express Lookahead multiple conditions -
my string looks this:
string = "*[eq](@[type],'a,b,c',@[type],*[eq](@[type],d,e,f))"
the ideal output list is:
['@[type]', 'a,b,c', '@[type]', '*[eq](@[type],d,e,f)']
so can parse string as:
if @[type] in ('a,b,c') @[type] else *[eq](@[type],d,e,f)
the challenge find commas followed @, ' or *. i've tried following code doesn't work:
interm = re.search(r"\*\[eq\]\((.+)(?=,@|,\*|,\')+,(.+)\)", string) print(interm.groups())
edit:
the ultimate goal parse out 4 components of input string:
*[eq](value, target, iftrue, iffalse)
>>> import re >>> string = "*[eq](@[type],'a,b,c',@[type],*[eq](@[type],d,e,f))" >>> re.split(r"^\*\[eq\]\(|\)$|,(?=[@'*])", string)[1:-1] ['@[type]', "'a,b,c'", '@[type]', '*[eq](@[type],d,e,f)']
although, if looking more robust solution i'd highly recommend lexical analyzer such flex.
Comments
Post a Comment