In Python, there is a better way for strings to parameterize strings in regular expressions than to do it manually:
test = 'flobalob'
names = ['a', 'b', 'c']
for name in names:
regexp = "%s" % (name)
print regexp, re.search(regexp, test)
This noddy example tries to match each name in turn. I know that it’s better to do this, but this is a simple example to illustrate this point.
The answer seems no, there is no real alternative. The best way to parameterize regular expressions in python is as above, or with derivatives like str.format(). I tried to write a general question, not "fix ma codez, thank you". For those who are interested, I gave an example that is closer to my needs:
for diskfilename in os.listdir(''):
filenames = ['bob.txt', 'fred.txt', 'paul.txt']
for filename in filenames:
name, ext = filename.split('.')
regexp = "%s.*\.%s" % (name, ext)
m = re.search(regexp, diskfilename)
if m:
print diskfilename, regexp, re.search(regexp, diskfilename)
"" <filename>_<date>.<extension>. filenames - dict, , .
, :
. - , . ( ).
. , .bak .. - , , , .
, . . fnmatch, .