I have string called “Micro(R) Windows explorer” in a text file How to search Case insensitive and (R) also match using Regular expression
code is
with open(logfile) as inf:
for line in inf:
if re.search(string,line,re.IGNORECASE):
print 'found line',line
but this string “Micro(R) Windows explorer” is not accepting giving error.
For a case-insensitive search, start your regex with
(?i)or compile it with there.Ioption.To match
(R), use the regex\(R\). Otherwise, the parentheses will be interpreted as regex metacharacters (meaning a capturing group), and only the string"MicroR Windows Explorer"would be matched by it.Together: