import re
filter_string = "(#1 AND #12) OR #10"
filters_array = [(1,"something"),(10,"something_another"),(12,"another_something")]
dt = dict(filters_array)
filter_string = re.sub(r'#([0-9]+)', lambda x: dt[int(x.group(1))] if int(x.group(1)) in dt else x.group(), filter_string)
print(filter_string)
aW1wb3J0IHJlCmZpbHRlcl9zdHJpbmcgPSAiKCMxIEFORCAjMTIpIE9SICMxMCIKZmlsdGVyc19hcnJheSA9IFsoMSwic29tZXRoaW5nIiksKDEwLCJzb21ldGhpbmdfYW5vdGhlciIpLCgxMiwiYW5vdGhlcl9zb21ldGhpbmciKV0KZHQgPSBkaWN0KGZpbHRlcnNfYXJyYXkpCmZpbHRlcl9zdHJpbmcgPSByZS5zdWIocicjKFswLTldKyknLCBsYW1iZGEgeDogZHRbaW50KHguZ3JvdXAoMSkpXSBpZiBpbnQoeC5ncm91cCgxKSkgaW4gZHQgZWxzZSB4Lmdyb3VwKCksIGZpbHRlcl9zdHJpbmcpCnByaW50KGZpbHRlcl9zdHJpbmcp