Rodriguez
Rodriguez

Reputation: 259

Obtain string inside curl bracket in python

Suppose I have a string like

{"", "b", "c"}, // we are here 

I would like to extract the {"", "b", "c"} and/or "", "b", "c" part of it. Is there any simple prescription for it?

Upvotes: 0

Views: 113

Answers (1)

Moses Koledoye
Moses Koledoye

Reputation: 78554

You can use regex - re.search:

import re

s = '{"", "b", "c"}, // we are here'
m = re.search(r'{.*}', s)
print(m.group(0))
#'{"", "b", "c"}'

{.*} matches every thing within the curly braces and the braces.

Upvotes: 1

Related Questions