How to Get Match Object When Searching For String in Python


In this example we will show how to get a match object when searching for a string in Python.

Source Code

import re

str1 = 'I love Python'

r = re.search('o', str1)

print(r)

Output:

<re.Match object; span=(3, 4), match='o'>
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments