import re
my_dict = {"X":"xxx", "Y":"yyy"}
my_str = "A[xxx]BC[yyy]"

def get_key_by_value(dictionary, value):
    for key, val in dictionary.items():
        if val == value:
            return key
    return value  # If no key has been found
        
rx = re.compile(r'\[([^][]*)]')
result_1 = rx.sub('', my_str)
result_2_arr = []
m = rx.search(my_str)
tmp = my_str
while m:
	result_2_arr.append("{}|{}".format(m.start(), get_key_by_value(my_dict, m.group(1))))
	tmp = "".join([tmp[:m.start()], tmp[m.end():]])
	m = rx.search(tmp)
	
print ( result_1 )
print ( "|".join(result_2_arr) )