Issue
import re
tenant_details = "Tasha Robinson (123) 4178-6875"
name = re.search("(?<=[a-zA-Z])(?=\d)",tenant_details)
print(name)
Required solution:
Name: Tasha Robinson
Phone No: (123) 4178-6875
The name can be full name or first name and phone number can be in any format like +1 854 545454
..
Solution
You can specify that phone number consists only from characters +()\d-
and spaces. Then you can use:
import re
tenant_details = "Tasha Robinson (123) 4178-6875"
name, phone = re.match(r"(.*?)\s([)(+\d -]+)$", tenant_details).groups()
print(f"{name=}")
print(f"{phone=}")
Prints:
name='Tasha Robinson'
phone='(123) 4178-6875'
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.