Question: Instructions: Using the text file provided, search for three patterns. o US National ID (Social Security Number): DDD-DD-DDDD or DDD.DD.DDDD. o US Phone number:

Instructions:
● Using the text file provided, search for three patterns.
o US National ID (Social Security Number): DDD-DD-DDDD or DDD.DD.DDDD.
o US Phone number: DDD-DDD-DDDD.
o US Postal Code (Zip Code): DDDDD or DDDDD-DDDD
Each D is a single digit (0-9).

The program will ask the user for the name of the file.
● The program will use RegEx objects to search for the provided patterns.
● The program will print out how many of each type of string was found.


Note: You may want to start using a shorter file for testing.

Here one of my python code:

import re

phone_numbers = []

pattern = r"\(([\d\-+]+)\)"

with open("log.txt", "r") as file:

for line in file:

result = re.search(pattern, line)

phone_numbers.append(result.group(1))

print(phone_numbers)

But I need to add in SSN and zip code.

This is the file name that has the ssn, phone number and zip code again.

Python\Lab 11 String Searches - numbers.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!