re basics

Regular expressions find patterns in text. The re functions you need most:

  • re.search(pattern, text) finds the first match anywhere, or returns None. Always check for None before calling .group().
  • re.findall(pattern, text) returns every match as a list of strings. If the pattern has one group in parentheses, you get just that group.

Common pieces: \d a digit, \w a letter, digit or underscore, \s whitespace, + one or more, * zero or more, {4} exactly four.

Write patterns as raw strings: r"\d+". In a normal string, Python treats backslashes as escapes first, so "\b" is a backspace character, not a word boundary.

Don't reach for regex when a string method will do. line.startswith("#"), "error" in line and line.split(",") are clearer and faster. And never parse HTML or JSON with regex: use a real parser.

Run it, then find every word that starts with a capital letter.