PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Regular Expressions in Python

← All stacks

Theory

88/268

Regular Expressions in Python

Regex finds text patterns. import re. re.search looks anywhere. re.match looks at the start. re.findall returns all matches. re.sub replaces. \d is a digit. \w is a word character. Use a raw string r"\d{10}" for a 10-digit mobile so backslashes stay sane.

Fresher example: re.findall(r"\d+", "Asha 90 Ravi 85") → ['90', '85']. Don’t parse a mobile with ten if-checks when one pattern works. search vs match: match only at the beginning.

Regular Expressions in Python — output — True then True. 10 digits; Asha letters only.

Exam tip

re.search vs re.match if asked.

Example

# Regex
import re
print(bool(re.fullmatch(r"\d{10}", "9876543210")))
print(bool(re.fullmatch(r"[A-Za-z]+", "Asha")))

Regular Expressions in Python — output: True then True. 10 digits; Asha letters only.

Short notes

  • Defimport re. Pattern match.
  • RuleUse r"..." raw strings.
  • Remembersearch vs match.

Questions

1

Explain Regular Expressions as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Regular Expressions?

Previous← Multiprocessing in PythonNextSend email →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.