I'm trying to modify certain lines present in a file. I'm searching for a text and replacing it.
For example, in the following code, I'm replacing vR33_ALAN with vR33_ALAN*c.
Here's my code for a test case
lines = ['x = vR32_ALEX - vR33_ALAN; \n',
'y = vR33_ALAN; \n']
text_to_search = 'vR33_ALAN'
replacement_text = 'vR33_ALAN*c'
for line in lines:
print(line.replace(text_to_search, replacement_text), end='')
I could succeed in performing the above task. I want to add one more check before replacing the string that matches text_to_search.
I want to replace text_to_search with replacement_text only if a minus - is NOT present proceeding text_to_search.
Example, The output that I obtain is
x = vR32_ALEX - vR33_ALAN*c;
y = vR33_ALAN*c;
Desired Output:
x = vR32_ALEX - vR33_ALAN;
y = vR33_ALAN*c;
I'm not sure how to achieve the above. Any suggestions?