Lazo Lab Sign up

Python Projects & Skills / Files and data

Lesson 15 of 28

Regular expressions

Regex finds patterns in text, like every email address or IP in a log file. Python's re module runs them.

Key points

  • \d digit, \w word char, + one or more
  • re.findall returns every match
  • Test patterns on regex101.com
import re
log = "Failed login from 10.0.0.5 and 10.0.0.9"
print(re.findall(r"\d+\.\d+\.\d+\.\d+", log))
Watch a video on thisOpens YouTube search results for “Regular expressions” in a new tab

Quiz · +10 XP

What does \d match in a regex?

Log in to save progress and earn XP.