Confusion while using regex to edit a key-value ini file (Python) -
i'm trying regex ante using edit .ini file based on vague descriptions of parts want changed.
specifically, i'm trying update line in file describes list of directories program use search vst libraries. i'm using following expression:
r"^(?=.*?vst.*?=)(?=.*?[(path)|(directories)].*?=)(?p<key>.*?)\s?=\s?(?p<value>.*)$"
i.e. i'm using lookaheads find out if there's mention of 'vst's alongside mention of 'path' or 'directories' before equals sign (indicating they're in key), , if match there i'm splitting result key-value groups.
however, i'm finding isn't working, , it's matching 'vst' in it.
is there i'm missing that's failing assert both lookaheads? (also not sure whether i've gone overboard question marks)
any appreciated
matt
figured out:
r"^(?=.*?vst.*?=)(?=.*?(?:path|directories).*?=)(?p<key>.*?)\s?=\s?(?p<value>.*)$"
what wrong was trying to "look 'path' or 'directories'" using
[(path)|(directories)]
...which incorrect because meant engine trying capture these conditional lookaheads groups. (not sure why didn't error though). correct way of asking use 'non-capturing group'
(?:path|directories)
Comments
Post a Comment