I'm creating a class that renames a file using a user-specified format. This format will be a simple string whose str.format method will be called to fill in the blanks.
It turns out that my procedure will require extracting variable names contained in braces. For example, a string may contain {user}, which should yield user. Of course, there will be several sets of braces in a single string, and I'll need to get the contents of each, in the order in which they appear and output them to a list.
Thus, "{foo}{bar}" should yield ['foo', 'bar'].
I suspect that the easiest way to do this is to use re.split, but I know nothing about regular expressions. Can someone help me out?
Thanks in advance!
str.format- it will ignore those not in pattern.'{user}_{bar}'.format(user='Mike', foo=1, bar=2)will outputMike_2. I happend to have allowed vars fixed in a dict, so I could skip looking for vars in pattern. Anyway knowing aboutstring.Formatter()is useful.