I have a file with some content as wells as the two 'include' strings below:
some string1
some string2
...
include: "base_pricing_app_model_my_deployment_id.model.lkml"
include: "base_map_layers.model.lkml"
...
some string3
...
Substring "my_deployment_id" is a token I need to add to the second 'include' string so file content looks like that:
some string1
some string2
...
include: "base_pricing_app_model_my_deployment_id.model.lkml"
include: "base_map_layers_my_deployment_id.model.lkml"
...
some string3
I am running Python 3.5 and using its re library. Here is how I attempt to replace the second 'include' string:
with fileinput.input(files=(rfi), inplace=True) as cmodf:
for line in cmodf:
match_no_dep_id = re.sub('^include:\s\"(?!my_deployment_id).*[.]model[.]lkml\"$', line.split('.')[0] + '_' + 'my_deployment_id' + 'model.lkml' + '"', line)
print(match_no_dep_id, end='')
However, both 'include' entries get modified and I end up with the following content:
some string1
some string2
include: "base_pricing_app_model_my_deployment_id_my_deployment_id.model.lkml"
include: "base_map_layers_my_deployment_id.model.lkml"
some string3
...
So my negative lookahead regexp matches both strings, including the one which already contains the token I am negating.
I am not sure what I am missing here. Please help.
Thank you!