Answers for "python regex get string between two strings"

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
0

replace string between two regex python

a = r''' Example
This is a very annoying string
that takes up multiple lines
and h@s a// kind{s} of stupid symbols in it
ok String'''

import re
re.sub('\nThis.*?ok','',a, flags=re.DOTALL)
' Example String'
Posted by: Guest on February-25-2021

Code answers related to "python regex get string between two strings"

Python Answers by Framework

Browse Popular Code Answers by Language