πŸ”’ Regex Day 1: Masking secret numbers


Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python.

​

Ever wondered how websites or apps identify a valid phone or email. Or mask sensitive info like SSN, passwords.

All this runs on regular expressions (regex) - patterns that describe text.

In Python, we use re module to search, extract, split and replace these patterns with ease.

​

πŸ‘‹ Basics - Import/Load the module

In: import re
Out:

​

🧐 Find if the word exists

In:
text = "I love Pandas Daily"
print(bool(re.search("Pandas", text)))
Out: True

​

⚠️ Is the search case-sensitive? No wonder..

In:
text = "I love Pandas Daily"
print(bool(re.search("pandas", text)))
Out: False

​

😏 When upper or lower case does not matter

In:
text = "I love Pandas Daily"
print(bool(re.search("pandas", text, re.IGNORECASE)))
Out: True

​

πŸ”’ Pattern (\d+) represents all numbers

In:
text = "Invoice 2025 is $300, due in 7 days"
print(re.findall(r"\d+", text))
Out: ['2025', '300', '7']

​

☎️ Extract phone number (format: xxx-xxx-xxxx)

d{n} means pattern of n digits together

In:
text = "My number is 123-456-7890"
print(re.findall(r"\d{3}-\d{3}-\d{4}", text))
Out: ['123-456-7890']

​

πŸ‘Ί Hide any sensitive info (ATM pins, SSN, passwords etc)

In:
text = "User pin is 4321"
print(re.sub(r"\d+", "***", text))
Out: User pin is ***

​

❇️ Coming up tomorrow - Extract emails!! Will use the below fundamental concept

In:
text = "Regex makes text easy!"
print(re.findall(r"\w+", text))
Out: ['Regex', 'makes', 'text', 'easy']

β­πŸ“£ That's it for today! If you liked it, please share it with anyone who will find it useful and share your feedback below 🐼

​

Pandas Daily

Beginner to Expert in Python in just 5 minutes

Read more from Pandas Daily

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. I am sure when you print C:\new_folder your code breaks due to \. Or you wonder how to print single (It's) or double ("Hello") quotes. Enter Escape Sequences, tiny backslash commands in Python that fix all of this. πŸ‘‰ Most common uses: Format using new lines Print tabs Single or double quotes in text Write file paths safely Print symbols like Ο€ or❀️ Let's Begin... πŸ‘‡ \n Print in next line - the one we all...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Think about the time you waste right-clicking and saving course lectures on YouTube one-by-one. Inefficient process, can cause errors and you lose focus. pytubefix eliminates that bottleneck. Today is day 3 of mastering YouTube with Python. You already know how to get stats of a single video; or download them in various formats. Now time to level up with playlists. Pytubefix has a Playlist object that...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Yesterday we introduced pytubefix - a powerful module to access YouTube. We downloaded a video as well. Cool, but basic. What if you want 1080p instead of 480p. Or prefer WebM over MP4. To answer all this - let's cover downloads in depth today. 🀫 I am 100% sure you can charm recruiters or your colleagues as they won't know this! πŸ“₯ Code Recap: How to download YouTube video In: # Import library from...