p = re.compile('A(?:(?![AC]).)*B(?:(?![AB]).)*C')
test_str = 'A|B|A|F|B|C|D|E|F|G'
result = re.sub(p, '[$0]', test_str)
test_str = 'A|B|C|F|B|C|D|E|F|G'
Mark the shortest overlapping match using regular expressions