如果我理解正确,这里不需要regex。
group_1 = ['brasil','argentina','chile','canada']
group_2 = ['brasil.sao_paulo','chile','argentina']
for x in group_1:
# For group 2 only, this picks out the part of the string that appears before the first ".".
if x in [y.split('.')[0] for y in group_2]:
print("Match: {}".format(x))
else:
print("Not match: {}".format(x))
又回来了
Match: brasil
Match: argentina
Match: chile
Not match: canada