Monday, July 27, 2026
HomeLanguagesre.fullmatch() function in Python

re.fullmatch() function in Python

re.fullmatch() returns a match object if and only if the entire string matches the pattern. Otherwise, it will return None. The flag at the end is optional and can be used to ignore cases etc. 

Syntax: re.fullmatch(pattern, string, flags=0)

Parameters:

  • pattern: the regular expression pattern that you want to match.
  • string: the string which you want to search for the pattern.
  • flags (optional argument): a more advanced modifier that allows you to customize the behavior of the function. 

Example 1:

Python3




import re
  
  
string = 'Lazyroar'
pattern = 'g...s'
  
print(re.fullmatch(pattern, string))


Output

<_sre.SRE_Match object; span=(0, 5), match='Lazyroar'>

Difference Between re.match() and re.fullmatch()

re.fullmatch() and re.match() both are functions of re module in python. These functions are very efficient and fast for searching in strings. Both functions attempt to match at the beginning of the string.  But the difference between re.match() and re.fullmatch() is that re.match() matches only at the beginning but re.fullmatch() tries to match at the end as well.

Example:

Python3




import re
  
  
string = "Geeks for Lazyroar"
pattern = "Geeks"
  
print(re.match(pattern, string))
print(re.fullmatch(pattern, string))


Output

<_sre.SRE_Match object; span=(0, 5), match='Geeks'>
None
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS