Multi-line regex with multiple matches and negative conditions in python -


i reading text file , attempting capture 1 of arguments of each distinct tag, has not been commented out.

more specifically, have following input...

maybe there text \thistag[arg1=1,argtwo]{want0} % \thistag[arg1=1,argtwo]{notwant} % blah blah \thistag[arg1=1,argtwo]{notwant} \thistag[arg1=1,argtwo]{want1}\thistag[arg1=1,argtwo]{want2}\\stuff \sometag{stuff don't want}[{\thistag[arg1=1,argtwo]{want3}}]{more stuff don't want} \thistag[arg1=1,argtwo]{obv_want} 

i want following output

want0 want1 want2 want3 obv_want 

so far have following code, doesn't accomplish want

with open(target, "r") ins:     f = re.findall(r'^(?:[^%])?\\thistag\[.+\]{(.+?)}(?:{.+})?', ins.read(),re.multiline) 

you regex line line filtering out ones start %:

import re  res = [] open('test.txt') f:     res = sum([re.findall('\\thistag\[.*?\]{(.*?)}', line)                 line in f if not line.startswith('%')               ], [])      print res # ['want0', 'want1', 'want2', 'want3', 'obv_want'] 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -