Take the following code:
import re
def test_targeting_file_matching():
a = "177"
b = "1"
filenames = ["177__1.csv", "177__1__000000000000.csv"]
targeting_file_pattern = re.compile(rf"{a}__{b}(__\d{12})?\.csv")
for filename in filenames:
if targeting_file_pattern.match(filename):
print(f"Matched: {filename}")
else:
print(f"Not Matched: {filename}")
test_targeting_file_matching()
It is supposed to match the two files, but only 177__1.csv is matched. I can't see the problem with my regex expression