Regular expression to return text between parenthesis


Question

u'abcde(date=\'2/xc2/xb2\',time=\'/case/test.png\')'

All I need is the contents inside the parenthesis.

1
81
2/13/2015 1:17:07 AM

Accepted Answer

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

s[s.find("(")+1:s.find(")")]
203
2/4/2011 3:03:24 AM

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'"

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon