Answers for "how to get text in between string python regex"

4

find text between two strings regex python

>>> import re
>>> s = 'Part 1. Part 2. Part 3 then more text'
>>> re.search(r'Part 1\.(.*?)Part 3', s).group(1)
' Part 2. '
>>> re.search(r'Part 1(.*?)Part 3', s).group(1)
'. Part 2. '
Posted by: Guest on May-18-2020

Code answers related to "how to get text in between string python regex"

Python Answers by Framework

Browse Popular Code Answers by Language