re.fullmatch

Full name
re.fullmatch
Library
re
Syntax

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

Description

The re.fullmatch function checks whether the entire text string satisfies the regular expression pattern, returning the corresponding match object. If the regular expression is not found, the function returns None.

Parameters
  • pattern: Search pattern.
  • string: Text in which to search.
  • flags: Search modifiers.
Result

The re.fullmatch function returns an object of type match or None if the regular expression is not satisfied.

Examples

We can check whether or not a full text satisfies a regular expression with the following code:

pattern = r'my (cat)s (is|are) pretty?'
text = 'my cats are pretty'
re.fullmatch(pattern, text)
<re.Match object; span=(0, 18), match='my cats are pretty'>

However, the following text does not satisfy the search pattern in its entirety, so the re.fullmatch function returns None (which is why nothing is displayed on the screen):

text = 'my cat is pretty and your cat is pretty'
re.fullmatch(pattern, text)
Submitted by admin on Mon, 05/17/2021 - 09:29