python re ignorecase code example

Example 1: python string match ignore case

if firstStr.lower() == secStr.lower():
    print('Both Strings are same')
else:
    print('Strings are not same')

Example 2: python re compile

import re
#	Compile a regular expression pattern into a regular expression object, which can be used for matching using its match(), search() and other methods, described below.

prog = re.compile(pattern)
result = prog.match(string)

#	is equivalent to

result = re.match(pattern, string)

Example 3: re module documentation

>>> m = re.search(r'(?<=-)\w+', 'spam-egg')
>>> m.group(0)
'egg'

Example 4: python string ignore characters

text = ['!kick', '/ban', '!k!ck']
for s in text:
    print s[0].translate(None, '!/') + s[1:]

output:
kick
ban
k!ck