In [1]:
import re
In [2]:
l = ['oneXXXaaa', 'twoXXXbbb', 'three999aaa', '000111222']
In [3]:
l_re_match = [s for s in l if re.match('.*XXX.*', s)]
print(l_re_match)
In [4]:
l_re_sub_all = [re.sub('(.*)XXX(.*)', r'\2---\1', s) for s in l]
print(l_re_sub_all)
In [5]:
l_re_sub = [re.sub('(.*)XXX(.*)', r'\2---\1', s) for s in l if re.match('.*XXX.*', s)]
print(l_re_sub)