Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Regular Expressions | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 24 of 55

·Python

Regular Expressions

20 minutes

Course progress44%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Use raw strings (`r'\d+'`) for regex patterns.
  • `re.search()` finds the first match anywhere in the string.
  • `re.findall()` returns all non‑overlapping matches.
  • `re.sub()` replaces matches with a replacement string.

Regular Expressions

The re module enables powerful pattern‑matching with regular expressions. Patterns are defined as raw strings (r'...') to avoid escaping backslashes.

import re
text = 'The price is $45.99.'
pattern = r'\d+\.\d{2}'  # matches numbers like 45.99
match = re.search(pattern, text)
if match:
    print('Found price:', match.group())

Common functions: re.search(), re.match(), re.findall(), re.sub().

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonWorking with JSONContinue to lesson 25OOP Basics – ClassesBack to Python Fundamentals curriculum