Python Practice › RegEx Programs › Program 20

Multiline and ignore-case flags

EasyRegEx Programs · 20 of 20

Write a Python program to find lines that start with “error” in any case.

Advertisement
Output
['Error: disk full', 'ERROR: timeout']

Approach

  1. re.M makes ^ match at every line start; re.I ignores case.

Solution

Python
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.

More regex programs

← All 20 RegEx Programs

Leave a Comment