Using look ahead and look behind in regex how can i replace the following words succefully using python without replacing other words that appear similar.
css = '''
selection-background-color: primary;
selection-background-color:primary;
selection-color: text-primary;
selection-background-color: primary-text;
'''
I was trying to use this (?<!\w)primary(?=\w)
based on what I was researching online but I'm not super familiar with regex and the best way to write this.
I would expect my results from the code above to create this...
css = css.replace('primary', 'rgb(255,255,255)')
css = css.replace('primary-text', 'red')
css = css.replace('text-primary', 'green')
returns:
css = '''
selection-background-color: rgb(255,255,255);
selection-background-color:rgb(255,255,255);
selection-color: green;
selection-background-color: red;
'''