re.IGNORECASE

Full name
re.IGNORECASE
Library
re
Syntax

re.IGNORECASE

Description

The re.IGNORECASE search modifier forces the function to which is applied to perform a case-insensitive search.

Parameters

The re.IGNORECASE search modifier takes no arguments.

Examples

If this modifier is not specified, the words "cat" and "CAt" are considered different:

pattern = r"(cat)s?"
text = 'my cat, your dog and his CAts play in the backyard'
re.findall(pattern, text)
['cat']

If, on the other hand, we add it as an argument to the function, the search is not case-sensitive:

re.findall(pattern, text, flags = re.IGNORECASE)
['cat', 'CAt']
Submitted by admin on Tue, 05/18/2021 - 08:57