Python Practice › RegEx Programs › Program 20
Multiline and ignore-case flags
Write a Python program to find lines that start with “error” in any case.
Output
['Error: disk full', 'ERROR: timeout']
Approach
re.Mmakes^match at every line start;re.Iignores case.
Solution
import re log = "Error: disk full\ninfo: ok\nERROR: timeout\nwarning: slow"print(re.findall(r"^error:.*$", log, flags=re.M | re.I))Output
['Error: disk full', 'ERROR: timeout']
Learn the concept
New to this topic? Read the lesson, then come back.