How can I substitute all occurrence of a certain string NOT after a specific character in Python?
For example, I want to substitute all occurrence of abc NOT with a x before them with def. Here is the code:
re.sub(r'(^|[^x])abc', r'\1def', string)
If the string doesn't have consecutive abcs, the code works perfectly. However, if I have string='abcabc', the code won't work. Is there any way to solve this problem?