How to Get Part of String Where There Was a Match in Python


In this example we will show how to get the part of the string where there was a match when searching for a string in Python.

Source Code

import re

str1 = 'I love Python'

r = re.search(r"bP.+", str1)

print(r.group())

Output:

Python
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments