Extract Python dictionary from string
<p>I have a string with valid python dictionary inside</p>

<pre><code>data = "Some string created {'Foo': u'1002803', 'Bar': 'value'} string continue etc."
</code></pre>

<p>I need to extract that dict. I tried with regex but for some reason <code>re.search(r"\{(.*?)\}", data)</code> did not work. Is there any better way extract this dict?</p>

<p>Your solution works!</p>

<pre><code>In [1]: import re

In [2]: data = "Some string created {'Foo': u'1002803', 'Bar': 'value'} string continue etc."

In [3]: a = eval(re.search(r"\{(.*?)\}", data).group(0))

In [4]: a
Out[4]: {'Bar': 'value', 'Foo': u'1002803'}
</code></pre>

python regex django dictionary django-views