Find String Match Pattern
I have a pattern like this: pattern = 'Delivered to %(recipient)s at %(location)s' How can I get the recipient and location of a string based on this pattern? For example: Deliver
Solution 1:
import re
pattern = 'Delivered to Mr.Smith at Seattle'
re.match(r'Delivered to (.*) at (.*)', pattern).groups()
('Mr.Smith', 'Seattle')
re.findall(r'Delivered to (.*) at (.*)', pattern)
[('Mr.Smith', 'Seattle')]
Post a Comment for "Find String Match Pattern"