Your desired output seems to be DE which is in bounded with two _ from left and right. This expression might also work:
# -*- coding: UTF-8 -*-
import re
string = "DC_QnA_bo_v.15.12.3_DE_duplicates.xlsx"
expression = r'_([A-Z]+)_'
match = re.search(expression, string)
if match:
print("YAAAY! \"" + match.group(1) + "\" is a match 💚💚💚 ")
else:
print('🙀 Sorry! No matches!')
Output
YAAAY! "DE" is a match 💚💚💚
Or you can add a 2 quantifier, if you might want:
# -*- coding: UTF-8 -*-
import re
string = "DC_QnA_bo_v.15.12.3_DE_duplicates.xlsx"
expression = r'_([A-Z]{2})_'
match = re.search(expression, string)
if match:
print("YAAAY! \"" + match.group(1) + "\" is a match 💚💚💚 ")
else:
print('🙀 Sorry! No matches!')

_is a word character, so\bwon't work_([A-Z]{2})instead with a capturing grouprgx = re.compile('_([A-Z]{2})')?re.findall(r'_([A-Z]{2})_', fn)will do, no need for any lookarounds