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 more
  • e - literal e
  • \+ - 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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -