Skip to main content

Python RegEx Match Object Functions

In Python, as we know, the match() and search() method returns a re.Match object if a match found. A Match Object is an object containing information about the search and the result.

If there is no match, the value "None" will be returned, instead of the Match Object.

The Match object has properties and methods used to give information about the search and the result:

  • .span(): It returns a tuple containing the start and end positions of the match
  • .string: It returns the string passed into the function
  • .group(): It returns the part of the string where there was a match


import re

str_1 = "Welcome to Python Programming "
res_1 ="\bP\w+", str_1)
res_2="\bP\w+", str_1)
res_3 ="\bP\w+", str_1)

(11, 17)
Welcome to Python Programming

Submitted by devanshi.srivastava on July 23, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.