forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegex_As_5.py
More file actions
23 lines (18 loc) · 1 KB
/
Regex_As_5.py
File metadata and controls
23 lines (18 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
''' We're working with a CSV file, which contains employee information. Each record
has a name field, followed by a phone number field, and a role field. The phone
number field contains U.S. phone numbers, and needs to be modified to the
international format, with "+1-" in front of the phone number. Fill in the
regular expression, using groups, to use the transform_record function to do
that. '''
import re
def transform_record(record):
new_record = re.sub(r"(\w*\s\w*),([\d-]+),(\w*\s\w*|\w*)",r"\1,+1-\2,\3",record)
return new_record
print(transform_record("Sabrina Green,802-867-5309,System Administrator"))
# Sabrina Green,+1-802-867-5309,System Administrator
print(transform_record("Eli Jones,684-3481127,IT specialist"))
# Eli Jones,+1-684-3481127,IT specialist
print(transform_record("Melody Daniels,846-687-7436,Programmer"))
# Melody Daniels,+1-846-687-7436,Programmer
print(transform_record("Charlie Rivera,698-746-3357,Web Developer"))
# Charlie Rivera,+1-698-746-3357,Web Developer