I think you're looking for this:
import re
FOO = """neighbors= {5 7 9 11 13 14 15 16 17 }"""
match = re.search('(neighbors\s*=\s*\{\s*(\d+\s*)+\})', FOO)
print match.group(1)
The regex is portable, of-course to many different languages.
Running that yields...
neighbors= {5 7 9 11 13 14 15 16 17 }
But the regex will match an arbitrary number of digits in curly-braces.
EDIT
Illustrating with re.findall()
and re.compile()
...
import re
FOO = """neighbors= {5 7 9 11 13 14 15 16 17 }"""
COMPILE = re.compile('(neighbors\s*=\s*\{\s*(\d+\s*)+\})')
match = re.findall(COMPILE, FOO)
print match[0]
Running the second code returns...
neighbors= {5 7 9 11 13 14 15 16 17 }
Although you should remember that .findall()
was meant for multiple occurrences of the regex match inside a target string. The examples provided have not illustrated a need for .findall()