python 2.7 - regex findall to retrieve a substring based on start and end character -
i have following string:
6[sup. 1e+02] i'm trying retrieve substring of 1e+02. variable first refers above specified string. below have tried.
re.findall(' \d*]', first)
you need use following regex:
\b\d+e\+\d+\b explanation:
\b- word boundary\d+- digits, 1 or moree- literale\+- literal+\d+- digits, 1 or more\b- word boundary
see demo
sample code:
import re p = re.compile(ur'\b\d+e\+\d+\b') test_str = u"6[sup. 1e+02]" re.findall(p, test_str) see ideone demo
Comments
Post a Comment