Regular expression to return text between parenthesis Regular expression to return text between parenthesis python-3.x python-3.x

Regular expression to return text between parenthesis


If your problem is really just this simple, you don't need regex:

s[s.find("(")+1:s.find(")")]


Use re.search(r'\((.*?)\)',s).group(1):

>>> import re>>> s = u'abcde(date=\'2/xc2/xb2\',time=\'/case/test.png\')'>>> re.search(r'\((.*?)\)',s).group(1)u"date='2/xc2/xb2',time='/case/test.png'"


If you want to find all occurences:

>>> re.findall('\(.*?\)',s)[u"(date='2/xc2/xb2',time='/case/test.png')", u'(eee)']>>> re.findall('\((.*?)\)',s)[u"date='2/xc2/xb2',time='/case/test.png'", u'eee']