How to write a case insensitive Python regular expression without re.compile?

PythonServer Side ProgrammingProgramming

We can pass re.IGNORECASE to the flags parameter of search, match, or sub −

Example

import re
print (re.search('bush', 'BuSh', re.IGNORECASE))
print (re.match('bush', 'BuSh', re.IGNORECASE))
print (re.sub('bush', 'xxxx', 'Bushmeat', flags=re.IGNORECASE))

Output

<_sre.SRE_Match object at 0x0000000005316648>
<_sre.SRE_Match object at 0x0000000005316648>
xxxxmeat
raja
Published on 03-Jan-2018 15:40:30
Advertisements