for value in ['%(a)s and %(b)s are friends.', '%%(nomatch)i', '%%',
    'Another %(matched)+4.5f%d%% example', '(%(should_match(but does not))s']:
    print(StringFormattingParser.getKeyNames(value))
print('%(should_match(but does not))s' % {'should_match(but does not)':
    'really does match'})
How to get the names of the named variables from the python string