Using capture group and findall:
>>> import re >>> s = """[34343] | ****. "Example": <one>, yellow dog ... tstring0 123 ... tstring1 456 ... tstring2 789""" >>> mydog = re.compile(', (.*)\n') >>> mydog.findall(s) ['yellow dog']
If you need only the first match, then:
>>> mydog.findall(s)[0] 'yellow dog'
Note: you must handle IndexError if s does not contain a match.
Chris seymour
source share