Problem
Given a file, for example:
#Example
x = 'foo = {}'
bar = {
'color': 'blue'
}
print('Hello World')
Using regular expressions, the program will find variables names that are corresponding to dictionaries or set literals and print them. The output for the above would just be:
bar
A line like this
yes = { "no={}" }
Should only return yes.
The variables could be found with \w+? expression I'm just not sure where to start.
Current code
for line in open('program.txt'):
array = line.split(' ')
for item in array:
if '{' in item:
print(array[0])
This only functions properly for basic examples and there are some problems. Multiable variables on the same line don't work either. Also it doesn't use Regular Expressions.